分类和带有胶卷的定制邮政类型

时间:2017-06-09 作者:Kleyton Renato

我在Bootstrap和Wordpress方面遇到了麻烦。

我想获得要展开的分类列表(显示分类中的自定义帖子)。但这很难!!!!

它基本上是一个自定义边栏

我的代码:

<h3>
    Portfólio
</h3>


<?php   

$catprod = get_terms( array(
            \'taxonomy\' => \'categoria-produto\',
            \'order\'    => \'DESC\'
     )); // Todas as categorias


$args = array(
      \'post_type\' => \'produto\'
     );

$prodtype = new WP_Query($args);


?>




   <div class="panel-group">

       <div class="panel-heading">
        <?php foreach( $catprod as $cat ) { ?>
           <h3 class="panel-title">
               <a data-toggle="collapse" href="#<?php echo $cat->slug ?>" class="accordion-toggle" data-parent="#accordion">
                  <?php echo $cat->name ?>
               </a>
           </h3>

           <div id="<?php echo $cat->slug ?>" class="panel-collapse collapse in">
             <div class="panel-body">
                  <?php foreach( $prodtype as $prod ) { ?>
                      <li>
                        <a href="<?php the_permalink() ?>">
                            <?php the_field(\'titulo\') ?>
                        </a>
                      </li>
                  <?php } ?>
             </div>
           </div>
        <?php } ?>  
       </div>  

   </div> 

2 个回复
SO网友:Bikash Waiba

你可以这样做

<h3>
    Portfólio
</h3>

<?php   

$catprod = get_terms( array(
            \'taxonomy\'  => \'categoria-produto\',
            \'order\'     => \'DESC\',
            \'parent\'    =>0, 
            \'hide_empty\' => false,
     )); // Todas as categorias




?>
   <div class="panel-group">

       <div class="panel-heading">
        <?php foreach( $catprod as $cat ): ?>
           <h3 class="panel-title">
               <a data-toggle="collapse" href="#<?php echo $cat->slug ?>" class="accordion-toggle" data-parent="#accordion">
                  <?php echo $cat->name ?>
               </a>
           </h3>
           <?php 

           $args = array(
                \'post_type\' => \'produto\',
                \'tax_query\' => array(
                        array(
                            \'taxonomy\' => \'categoria-produto\',
                            \'terms\' => $cat->slug,
                            \'field\' => \'slug\',
                            \'include_children\' => true,
                            \'operator\' => \'IN\'
                        )
                    ),

             );

            $prodtype = new WP_Query($args);

           ?>
           <div id="<?php echo $cat->slug ?>" class="panel-collapse collapse in">
             <div class="panel-body">
                  <?php while( $query->have_posts() ):$query->the_post(); ?>
                      <li>
                        <a href="<?php the_permalink() ?>">
                            <?php the_title(); ?>
                        </a>
                      </li>
                  <?php endwhile; wp_reset_postdata(); ?>
             </div>
           </div>
        <?php endforeach; ?>  
       </div>  

   </div> 

SO网友:Kleyton Renato
Now it works...

<h3>
    Portfólio
</h3>


<?php   

$catprod = get_terms( array(
            \'taxonomy\' => \'categoria-produto\',
            \'order\'    => \'DESC\'
     )); 


?>




   <div class="panel-group">

       <div class="panel-heading">

        <?php foreach( $catprod as $cat ) { ?>
           <h3 class="panel-title">
               <a data-toggle="collapse" href="#<?php echo $cat->slug ?>" class="accordion-toggle" data-parent="#accordion">
                  <?php echo $cat->name ?>
               </a>
           </h3>

                <!-- expand -->
                   <div id="<?php echo $cat->slug ?>" class="panel-collapse collapse in">
                <?php //foreach( $catprod as $prod ) { ?> 

                        <?php   
                        $args = array(
                            \'post_type\' => \'produto\',
                            //\'posts_per_page\' => 6,
                            \'orderby\' => \'title\',
                            \'order\' => \'ASC\',
                            \'tax_query\' => array(
                                array(
                                    \'taxonomy\' => \'categoria-produto\',
                                    \'field\' => \'slug\',
                                    \'terms\' => $cat->slug
                                )
                            )
                        );
                        $content = new WP_Query( $args );       
                        ?>                            

                     <div class="panel-body">
                       <?php while ( $content->have_posts() ) : $content->the_post(); ?>                         
                          <li>
                            <a href="<?php the_permalink() ?>">
                                <?php the_field(\'titulo\') ?>
                            </a>
                          </li>
                       <?php endwhile; ?>
                       <?php wp_reset_query() ?>                                  
                     </div>


                <?php //} ?>
                   </div>
                <!--/expand -->   

        <?php } ?>  


       </div>  

   </div> 

结束