【问题标题】:How to display all post in wordpress, i am using pagination, so its display the post that display as per page no other of navigation other page如何在wordpress中显示所有帖子,我正在使用分页,所以它显示按页面显示的帖子,没有其他导航页面
【发布时间】:2018-02-19 11:18:37
【问题描述】:

任何 WordPress 专家,请帮助我。

我试图在下拉菜单中显示所有帖子,我得到下拉选项的结果 12 结果,但另一个第二页(我正在使用分页)帖子没有显示在下拉菜单中,当我转到第二页我显示该页面发布下拉结果。我想在每个页面页面的下拉菜单中显示所有帖子。

代码:-

<?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>

【问题讨论】:

  • 'brands')); ?>

标签: php wordpress


【解决方案1】:

在这里你调用了函数,但你没有为任何变量分配返回值:

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

将其编辑为:

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

函数 wp_list_pages 返回 HTML 格式的字符串 https://developer.wordpress.org/reference/functions/wp_list_pages/。你不需要循环它,只需回显它:

<?php echo $dropdown_posts ?>

如果您更愿意循环浏览帖子,请使用 get_posts() 函数,如下所示:

<?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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    • 2015-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多