2017-04-10 1 views
0

J'ai une page avec 4 onglets de bootstrap. Chaque onglet doit contenir des publications de type publication personnalisée dans une catégorie différente. 4 catégories, 4 onglets. Cela devrait être vraiment facile en utilisant in_category(); mais pour une raison quelconque, je ne peux filtrer que pour le premier onglet. Les trois autres onglets ne montrent aucun message.La boucle de poteau dans le filtre de catégorie ne fonctionne pas

S'il vous plaît voir cette question pour mon approche: Creating if statements to filter posts by category from cpt in wordpress

Voici le code de l'archive-journal.php, où est mon journal cpt. J'utilise des champs personnalisés avancés.

PHP

<!-- Tab panes --> 
<div class="tab-content"> 

    <?php if (have_posts()) : ?> 


      <!-- cambridge winter college --> 
      <div role="tabpanel" class="tab-pane active" id="tab1"> 
       <!-- accordian --> 
        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> 
         <?php $entry_count = 0; ?> 
         <?php while (have_posts()) : the_post(); ?> 
          <?php if (in_category('cambridge-winter-college')) : ?> 

           <?php $entry_count++; ?> 

           <!-- entry --> 
           <div class="entry"> 
            <div class="col-lg-3 date"> 
             <time class="cbp_tmtime"><span><?php the_field('day'); ?></span><br> <span><?php the_field('date'); ?><sup><?php the_field('suffix'); ?></sup> <?php the_field('month'); ?></span> </time> 
             <div class="cbp_tmicon"></div> 
            </div> 

            <div class="panel-heading panel-head col-lg-9"> 
             <a data-toggle="collapse" data-parent="#accordion" href="#collapse-cw-<?php echo $entry_count; ?>"> 
              View <?php the_field('day'); ?>'s journal entry 
             </a> 
            </div> 

            <div id="collapse-cw-<?php echo $entry_count; ?>" class="panel-collapse collapse in col-lg-12 pull-right"> 
             <div class="panel-body col-lg-9 pull-right"> 
             <div class="row"> 
              <div class="col-lg-12 entry-text"> 

               <aside class="col-lg-6 pull-right flexbox-2">  
                <div class="schedule" > 
                 <?php $table = get_field('schedule'); 
                  if ($table) { 
                   echo '<table>'; 
                    if ($table['header']) { 
                     echo '<thead><tr>'; 
                      echo ''; 
                       foreach ($table['header'] as $th) { 
                        echo '<th>'; 
                         echo $th['c']; 
                        echo '</th>'; 
                       } 
                      echo '</tr>'; 
                     echo '</thead>'; 
                    } 

                    echo '<tbody>'; 
                     foreach ($table['body'] as $tr) { 
                      echo '<tr>'; 
                       foreach ($tr as $td) { 
                        echo '<td>'.$td['c'].'</td>'; 
                       } 
                      echo '</tr>'; 
                     } 
                    echo '</tbody>'; 
                   echo '</table>'; 
                  } ?> 
                </div> 
                <?php if (the_field('fun_fact')) { ?> 
                <div class="fun-fact" style=""> 
                 <?php the_field('fun_fact'); ?> 
                </div> 
                <?php } ?> 
               </aside> 

               <div class="flexbox-1"> 
                <?php the_field('entry_text'); ?> 
               </div> 

              </div>       
             </div> 

             <div class="row carousel-wrapper"> 

              <div id="carousel-cw-<?php echo $entry_count; ?>" class="carousel slide" data-ride="carousel">       

               <div class="carousel-inner" role="listbox"> 

                <?php if (have_rows('slider')) : ?> 
                <?php $image_count = 0 ?> 
                <?php while (have_rows('slider')) : the_row(); ?> 
                <?php $image_count++; ?>  
                 <?php if (get_sub_field('image')) { ?> 
                  <div class="item <?php if ($image_count == 1) echo 'active' ?>"> 
                   <img src="<?php the_sub_field('image'); ?>" title=""> 
                   <figcaption><?php the_sub_field('caption'); ?></figcaption> 
                  </div> 
                 <?php } ?> 
                <?php endwhile; ?> 
               <?php else : ?> 
                <?php // no rows found ?> 
               <?php endif; ?> 

               <a class="left carousel-control" href="#carousel-cw-<?php echo $entry_count; ?>" role="button" data-slide="prev"> 
               <span class="fa fa-chevron-left glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 
               <span class="sr-only">Previous</span> 
               </a> 
               <a class="right carousel-control" href="#carousel-cw-<?php echo $entry_count; ?>" role="button" data-slide="next"> 
               <span class="fa fa-chevron-right glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
               <span class="sr-only">Next</span> 
               </a> 
              </div> 
              <!--/carousel --> 

             </div> 
             </div> 
            </div> 

           </div> 

          </div> 
          <!-- /entry --> 



          <?php endif; ?> 
         <?php endwhile; ?> 
        </div> 
       <!--/accordian --> 
       <div class="terminator"></div> 
      </div> 
      <!--/cambridge winter college --> 



      <!-- oxford summer 1 --> 
      <div role="tabpanel" class="tab-pane" id="tab2"> 
       <!-- accordian --> 
        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> 

         <?php $entry_count = 0; ?> 
         <?php while (have_posts()) : the_post(); ?> 
          <?php if (in_category('oxford_summer_college_1')) : ?> 

           <?php $entry_count++; ?> 


           <!-- entry --> 
           <div class="entry"> 
            <div class="col-lg-3 date"> 
             <time class="cbp_tmtime"><span><?php the_field('day'); ?></span><br> <span><?php the_field('date'); ?><sup><?php the_field('suffix'); ?></sup> <?php the_field('month'); ?></span> </time> 
             <div class="cbp_tmicon"></div> 
            </div> 

            <div class="panel-heading panel-head col-lg-9"> 
             <a data-toggle="collapse" data-parent="#accordion" href="#collapse-os1-<?php echo $entry_count; ?>"> 
              View <?php the_field('day'); ?>'s journal entry 
             </a> 
            </div> 

            <div id="collapse-os1-<?php echo $entry_count; ?>" class="panel-collapse collapse in col-lg-12 pull-right"> 
             <div class="panel-body col-lg-9 pull-right"> 
             <div class="row"> 
              <div class="col-lg-12 entry-text"> 

               <aside class="col-lg-6 pull-right flexbox-2">  
                <div class="schedule" > 
                 <?php $table = get_field('schedule'); 
                  if ($table) { 
                   echo '<table>'; 
                    if ($table['header']) { 
                     echo '<thead><tr>'; 
                      echo ''; 
                       foreach ($table['header'] as $th) { 
                        echo '<th>'; 
                         echo $th['c']; 
                        echo '</th>'; 
                       } 
                      echo '</tr>'; 
                     echo '</thead>'; 
                    } 

                    echo '<tbody>'; 
                     foreach ($table['body'] as $tr) { 
                      echo '<tr>'; 
                       foreach ($tr as $td) { 
                        echo '<td>'.$td['c'].'</td>'; 
                       } 
                      echo '</tr>'; 
                     } 
                    echo '</tbody>'; 
                   echo '</table>'; 
                  } ?> 
                </div> 
                <div class="fun-fact" style=""> 
                 <?php the_field('fun_fact'); ?> 
                </div> 
               </aside> 

               <div class="flexbox-1"> 
                <?php the_field('entry_text'); ?> 
               </div> 

              </div>       
             </div> 

             <div class="row carousel-wrapper"> 

              <div id="carousel-os1-<?php echo $entry_count; ?>" class="carousel slide" data-ride="carousel">       

               <div class="carousel-inner" role="listbox"> 

                <?php if (have_rows('slider')) : ?> 
                <?php $image_count = 0 ?> 
                <?php while (have_rows('slider')) : the_row(); ?> 
                <?php $image_count++; ?>  
                 <?php if (get_sub_field('image')) { ?> 
                  <div class="item <?php if ($image_count == 1) echo 'active' ?>"> 
                   <img src="<?php the_sub_field('image'); ?>"> 
                   <figcaption><?php the_sub_field('caption'); ?></figcaption> 
                  </div> 
                 <?php } ?> 
                <?php endwhile; ?> 
               <?php else : ?> 
                <?php // no rows found ?> 
               <?php endif; ?> 

               <a class="left carousel-control" href="#carousel-os1-<?php echo $entry_count; ?>" role="button" data-slide="prev"> 
               <span class="fa fa-chevron-left glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 
               <span class="sr-only">Previous</span> 
               </a> 
               <a class="right carousel-control" href="#carousel-os1-<?php echo $entry_count; ?>" role="button" data-slide="next"> 
               <span class="fa fa-chevron-right glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
               <span class="sr-only">Next</span> 
               </a> 
              </div> 
              <!--/carousel --> 

             </div> 
             </div> 
            </div> 

           <!-- </div> --> 

          </div> 
          <!-- /entry --> 



          <?php endif; ?> 
         <?php endwhile; ?> 
        </div> 
       <!--/accordian --> 
       <div class="terminator"></div> 
      </div> 
      <!--/oxford summer 1 --> 


      <!-- oxford summer college 2 --> 
      <div role="tabpanel" class="tab-pane" id="tab3"> 
       <!-- accordian --> 
        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> 
         <?php $entry_count = 0; ?> 
         <?php while (have_posts()) : the_post(); ?> 
          <?php if (in_category('oxford_summer_college_2')) : ?> 

           <?php $entry_count++; ?> 

           <!-- entry --> 
           <div class="entry"> 
            <div class="col-lg-3 date"> 
             <time class="cbp_tmtime"><span><?php the_field('day'); ?></span><br> <span><?php the_field('date'); ?><sup><?php the_field('suffix'); ?></sup> <?php the_field('month'); ?></span> </time> 
             <div class="cbp_tmicon"></div> 
            </div> 

            <div class="panel-heading panel-head col-lg-9"> 
             <a data-toggle="collapse" data-parent="#accordion" href="#collapse-os2-<?php echo $entry_count; ?>"> 
              View <?php the_field('day'); ?>'s journal entry 
             </a> 
            </div> 

            <div id="collapse-os2-<?php echo $entry_count; ?>" class="panel-collapse collapse in col-lg-12 pull-right"> 
             <div class="panel-body col-lg-9 pull-right"> 
             <div class="row"> 
              <div class="col-lg-12 entry-text"> 

               <aside class="col-lg-6 pull-right flexbox-2">  
                <div class="schedule" > 
                 <?php $table = get_field('schedule'); 
                  if ($table) { 
                   echo '<table>'; 
                    if ($table['header']) { 
                     echo '<thead><tr>'; 
                      echo ''; 
                       foreach ($table['header'] as $th) { 
                        echo '<th>'; 
                         echo $th['c']; 
                        echo '</th>'; 
                       } 
                      echo '</tr>'; 
                     echo '</thead>'; 
                    } 

                    echo '<tbody>'; 
                     foreach ($table['body'] as $tr) { 
                      echo '<tr>'; 
                       foreach ($tr as $td) { 
                        echo '<td>'.$td['c'].'</td>'; 
                       } 
                      echo '</tr>'; 
                     } 
                    echo '</tbody>'; 
                   echo '</table>'; 
                  } ?> 
                </div> 
                <div class="fun-fact" style=""> 
                 <?php the_field('fun_fact'); ?> 
                </div> 
               </aside> 

               <div class="flexbox-1"> 
                <?php the_field('entry_text'); ?> 
               </div> 

              </div>       
             </div> 

             <div class="row carousel-wrapper"> 

              <div id="carousel-os2-<?php echo $entry_count; ?>" class="carousel slide" data-ride="carousel">       

               <div class="carousel-inner" role="listbox"> 

                <?php if (have_rows('slider')) : ?> 
                <?php $image_count = 0 ?> 
                <?php while (have_rows('slider')) : the_row(); ?> 
                <?php $image_count++; ?>  
                 <?php if (get_sub_field('image')) { ?> 
                  <div class="item <?php if ($image_count == 1) echo 'active' ?>"> 
                   <img src="<?php the_sub_field('image'); ?>"> 
                   <figcaption><?php the_sub_field('caption'); ?></figcaption> 
                  </div> 
                 <?php } ?> 
                <?php endwhile; ?> 
               <?php else : ?> 
                <?php // no rows found ?> 
               <?php endif; ?> 

               <a class="left carousel-control" href="#carousel-os2-<?php echo $entry_count; ?>" role="button" data-slide="prev"> 
               <span class="fa fa-chevron-left glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 
               <span class="sr-only">Previous</span> 
               </a> 
               <a class="right carousel-control" href="#carousel-os2-<?php echo $entry_count; ?>" role="button" data-slide="next"> 
               <span class="fa fa-chevron-right glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
               <span class="sr-only">Next</span> 
               </a> 
              </div> 
              <!--/carousel --> 

             </div> 
             </div> 
            </div> 

           </div> 

          </div> 
          <!-- /entry --> 



          <?php endif; ?> 
         <?php endwhile; ?> 
        </div> 
       <!--/accordian --> 
       <div class="terminator"></div> 
      </div> 
      <!--/oxford summer college 2 --> 

      <!-- cambridge summer college --> 
      <div role="tabpanel" class="tab-pane" id="tab4"> 
       <!-- accordian --> 
        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> 
         <?php $entry_count = 0; ?> 
         <?php while (have_posts()) : the_post(); ?> 
          <?php if (in_category('cambridge_summer_college')) : ?> 

           <?php $entry_count++; ?> 

           <!-- entry --> 
           <div class="entry"> 
            <div class="col-lg-3 date"> 
             <time class="cbp_tmtime"><span><?php the_field('day'); ?></span><br> <span><?php the_field('date'); ?><sup><?php the_field('suffix'); ?></sup> <?php the_field('month'); ?></span> </time> 
             <div class="cbp_tmicon"></div> 
            </div> 

            <div class="panel-heading panel-head col-lg-9"> 
             <a data-toggle="collapse" data-parent="#accordion" href="#collapse-cs-<?php echo $entry_count; ?>"> 
              View <?php the_field('day'); ?>'s journal entry 
             </a> 
            </div> 

            <div id="collapse-cs-<?php echo $entry_count; ?>" class="panel-collapse collapse in col-lg-12 pull-right"> 
             <div class="panel-body col-lg-9 pull-right"> 
             <div class="row"> 
              <div class="col-lg-12 entry-text"> 

               <aside class="col-lg-6 pull-right flexbox-2">  
                <div class="schedule" > 
                 <?php $table = get_field('schedule'); 
                  if ($table) { 
                   echo '<table>'; 
                    if ($table['header']) { 
                     echo '<thead><tr>'; 
                      echo ''; 
                       foreach ($table['header'] as $th) { 
                        echo '<th>'; 
                         echo $th['c']; 
                        echo '</th>'; 
                       } 
                      echo '</tr>'; 
                     echo '</thead>'; 
                    } 

                    echo '<tbody>'; 
                     foreach ($table['body'] as $tr) { 
                      echo '<tr>'; 
                       foreach ($tr as $td) { 
                        echo '<td>'.$td['c'].'</td>'; 
                       } 
                      echo '</tr>'; 
                     } 
                    echo '</tbody>'; 
                   echo '</table>'; 
                  } ?> 
                </div> 
                <div class="fun-fact" style=""> 
                 <?php the_field('fun_fact'); ?> 
                </div> 
               </aside> 

               <div class="flexbox-1"> 
                <?php the_field('entry_text'); ?> 
               </div> 

              </div>       
             </div> 

             <div class="row carousel-wrapper"> 

              <div id="carousel-cs-<?php echo $entry_count; ?>" class="carousel slide" data-ride="carousel">       

               <div class="carousel-inner" role="listbox"> 

                <?php if (have_rows('slider')) : ?> 
                <?php $image_count = 0 ?> 
                <?php while (have_rows('slider')) : the_row(); ?> 
                <?php $image_count++; ?>  
                 <?php if (get_sub_field('image')) { ?> 
                  <div class="item <?php if ($image_count == 1) echo 'active' ?>"> 
                   <img src="<?php the_sub_field('image'); ?>"> 
                   <figcaption><?php the_sub_field('caption'); ?></figcaption> 
                  </div> 
                 <?php } ?> 
                <?php endwhile; ?> 
               <?php else : ?> 
                <?php // no rows found ?> 
               <?php endif; ?> 

               <a class="left carousel-control" href="#carousel-cs-<?php echo $entry_count; ?>" role="button" data-slide="prev"> 
               <span class="fa fa-chevron-left glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 
               <span class="sr-only">Previous</span> 
               </a> 
               <a class="right carousel-control" href="#carousel-cs-<?php echo $entry_count; ?>" role="button" data-slide="next"> 
               <span class="fa fa-chevron-right glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
               <span class="sr-only">Next</span> 
               </a> 
              </div> 
              <!--/carousel --> 

             </div> 
             </div> 
            </div> 

           </div> 

          </div> 
          <!-- /entry --> 



          <?php endif; ?> 
         <?php endwhile; ?> 
        </div> 
       <!--/accordian --> 
       <div class="terminator"></div> 
      </div> 
      <!-- /cambridge summer college --> 


    <?php endif; ?> 

</div> 
<!--/tab content --> 

Désolé pour le long dépôt de code, mais il est fondamentalement la même et copiée 4 fois. Vraiment je ne peux pas voir ce qui ne va pas ici. Tout avis serait grandement apprécié.

+0

S'il vous plaît partager résultat de 'print_r (get_querried_object());' – BlueSuiter

+1

double possible de [Création d'instruction if pour filtrer les messages par catégorie de cpt à wordpress] (http://stackoverflow.com/questions/43312949/create-if-statements-to-filter-posts-by-category-from-cpt-in-wordpress) –

+0

J'ai placé print_r juste avant le moment du second onglet. J'ai eu ceci: Erreur fatale: Appel à la fonction indéfinie get_querried_object() – vincentieo

Répondre

0

Une solution étonnamment simple. J'ai eu les messages max mis à 10. Vraiment une erreur évidente que je suis tombé en faute à quelques reprises. Simplement changer les messages max fait le tour mais vu que je veux avoir un blog ainsi que la pagination, j'ai ajouté ce qui suit des astuces css pour activer tous les messages de mon CPT. Cpt est Journal.

PHP

// CPT all posts in Archive layout 
function set_posts_per_page_for_journal_cpt($query) { 
    if (!is_admin() && $query->is_main_query() && is_post_type_archive('journal')) { 
    $query->set('posts_per_page', '-1'); 
    } 
} 
add_action('pre_get_posts', 'set_posts_per_page_for_journal_cpt'); 

?>