Изотоп + категория get_theme_mod не фильтруется - PullRequest
0 голосов
/ 21 октября 2018

Добрый день, я следовал за изотопной статьей Алисии Рамирес

https://www.aliciaramirez.com/2014/03/integrating-isotope-with-wordpress/

То, чего я хочу достичь, похоже на статью, но вместо предопределенной категории я использую настройщик / get_theme_mode(категория портфолио) в качестве фильтра категории.Категория работает и отображает все сообщения из всех категорий, однако ссылка на категорию не передается в список категорий <li>links</li>

Ниже приведен код Алисии Рамизез

     <div id="test" class="sectionpadding bg-warning">
        <ul id="filters">
          <li><a href="#" data-filter="*">Everything</a></li>
                 <?php
                 $categories=get_categories(
                   array( 'parent' => $cat->cat_ID,
                  'parent' => get_theme_mod('portfolio_category'),
                  ));
                  var_dump($categories);
                 $terms = get_terms('category', array('parent' =>  
        get_theme_mod('portfolio_category'))); // you can use any taxonomy, 
       instead of just 'category'
                 $count = count($terms); //How many are they?
                 if ( $count > 0 )
                     {  //If there are more than 0 terms
                         foreach ( $terms as $term ) {  //for each term:
                            echo "<li><a href='#' data-filter='.".$term->slug."'>" . $term->name . "</a></li>\n";                         //create a list item with the current term slug for sorting, and name for label
                                                    }
                     }
                 ?>
        </ul>

  <?php
     $terms_ID_array = array();
     foreach ($terms as $term)
     {
         $terms_ID_array[] = $term->term_id; // Add each term's ID to an array
     }
     $terms_ID_string = implode(',', $terms_ID_array); // Create a string with all the IDs, separated by commas
     $the_query = new WP_Query( '
     posts_per_page=50&cat='.$terms_ID_string ); // Display 50 posts that belong to the categories in the string ?>

     <?php if ( $the_query->have_posts() ) : ?>
    <div id="isotope-list">
      <?php
      while ( $the_query->have_posts() ) : $the_query->the_post();
      $termsArray = get_the_terms( $post->ID, "category" );  //Get the terms for this particular item
      $termsString = ""; //initialize the string that will contain the terms
      foreach ( $termsArray as $term ) { // for each term
        $termsString .= $term->slug.' '; //create a string that has all the slugs
      }
      ?>
      <div class="<?php echo $termsString; ?> item"> <?php // 'item' is used as an identifier (see Setp 5, line 6) ?>
        <h3><?php the_title(); ?></h3>
         <?php
              if ( has_post_thumbnail() ) {
                      the_post_thumbnail();
                } ?>
                </div> <!-- end item -->
              <?php endwhile;  ?>
            </div> <!-- end isotope-list -->
<?php endif; ?>
</div>


my jquery enqueue script

        function add_isotope() {
    wp_register_script( 'isotope', get_template_directory_uri().'/inc/asssets/js/jquery.isotope.js', array('jquery'),  true );
    wp_register_script( 'isotope-init', get_template_directory_uri().'/inc/asssets/js/isotope.js', array('jquery', 'isotope'),  true );
    wp_register_style( 'isotope-css', get_stylesheet_directory_uri() . '/inc/asssets/css/isotope.css' );

    wp_enqueue_script('isotope-init');
    wp_enqueue_style('isotope-css');
}

add_action( 'wp_enqueue_scripts', 'add_isotope' );

спасибо

...