繁体   English   中英

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

[英]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专家,请帮助我。

我试图显示下拉菜单中的所有帖子,但我得到下拉选项的结果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>

在这里,您调用了function,但没有将返回值分配给任何变量:

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM