.addClass on functions.php

时间:2018-08-22 08:59:03

标签: javascript php jquery wordpress

我不知道如何解决这个问题。在header.php中,我有这个javascript

  <script language="javascript">
     $(document).ready(function() {
        $(".catfilter").click(function(){
           $("#category-post-content").addClass("shownewsajax");
           $(".sasasa").addClass("rrrrrrrrrrrr");
     });     
    }); 
    </script>    

它非常适合#category-post-content,但是由于“ sasasa”元素位于functions.php中(进入add_action函数),因此不会在.catfilter单击上添加类“ rrrrrrrr”。

即使在class.functions.php中需要类的元素,如何使它起作用的任何想法?

这是functions.php中.sasasa所在的代码

///Ajax post filtering by category
 add_action( 'wp_ajax_load-filter', 'prefix_load_cat_posts' );
 function prefix_load_cat_posts () { ?>
 <div class="allposts row blogrow">
 <?php ob_start ();
 $query = new WP_Query(
    $args = array (
    'showposts' => 999,
    'cat' => $cat_id = $_POST[ 'cat' ]
 )  );
 $posts = get_posts( $args );
  foreach ( $posts as $post ) {
 setup_postdata( $post );
 ?>

<div class="sasasa news-wrap">  
<div class="newsflex">
<div class="postfeat"> <?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID ), 'my-custom-thumb' ); ?>
<img src="<?php echo $image[0]; ?>">
<?php endif; ?> 
 </div>
 <div class="postinfo">
 <div class="postcat">
 <?php foreach( (get_the_category($post)) as $category) { ?> <?php echo $category->cat_name; ?><?php } ?>
 </div>
 <h4 class="newstitle"><?php echo $post->post_title; ?></h4>
 <div class="postexc"><?php $excerpt = get_the_excerpt($post); echo   $excerpt;?></div>
 <a href="<?php echo get_permalink; ?>">READ MORE <span    class="rightarrow"></span></a>
 </div>
 </div>
  </div>


 <?php
 } wp_reset_postdata(); ?>
</div>
<div class="next-button"><a href="#" id="loadMoreCat">Load More Posts    CAT</a></div>

  <? $response = ob_get_contents();
  ob_end_clean();

   echo $response;
  die(1);
  } 

0 个答案:

没有答案