donglun1020 2018-02-19 11:18
浏览 83
已采纳

如何显示wordpress中的所有帖子,我正在使用分页,所以它显示的帖子显示为每页没有其他导航其他页面

Any WordPress experts, Please Help me.

I am trying to display all posts in the drop-down menu, I get result 12 results of drop-down options, but another second page (I am using pagination) post is not shown in the drop down menu, when I go to the second page I show that page posts dropdown result. I want to show all posts in the dropdown menu on every page pages.

Code:-

<?php 

 wp_list_pages(array('post_type'=>'brands')); 

?> 
<select class="form-control pdt-category-select search-space" id="brands" name="brands"> 
   <option>All</option> 
   <?php foreach ($posts as $post) { 
     echo '<option value="', $post->post_name, '"', $selected == $post->ID ? ' selected="selected"' : '', '>', $post->post_title, '</option>'; 
   }?> 
</select>
  • 写回答

1条回答 默认 最新

  • douzi1991 2018-02-19 12:02
    关注

    Here you called function but you didn't assign return value to any variable:

    wp_list_pages(array('post_type'=>'brands'));
    

    Edit it to:

    $dropdown_posts = wp_list_pages(array('post_type'=>'brands'));
    

    Function wp_list_pages is returning string in HTML format https://developer.wordpress.org/reference/functions/wp_list_pages/. You don't need to loop it, just echo it:

    <?php echo $dropdown_posts ?>
    

    If you rather loop through posts use function get_posts() like this:

    <?php 
    
     $dropdown_posts = get_posts(array('post_type'=>'brands')); 
    
    ?> 
    <select class="form-control pdt-category-select search-space" id="brands" name="brands"> 
       <option>All</option> 
       <?php foreach ($dropdown_posts as $post) { 
         echo '<option value="', $post->post_name, '"', $selected == $post->ID ? ' selected="selected"' : '', '>', $post->post_title, '</option>'; 
       }?> 
    </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址