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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料