如何显示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>
任何WordPress专家,请帮助我。 p>
我正在尝试在下拉菜单中显示所有帖子,我得到结果12下拉选项的结果,但另一个第二页(我正在使用分页)帖子未显示 在下拉菜单中,当我转到第二页时,我显示该页面的帖子下拉结果。 我想在每个页面的下拉菜单中显示所有帖子。 p>
代码: - p>
&lt;?php
\ n wp_list_pages(array('post_type'=&gt;'brands'));
&GT?;
&lt; select class =“form-control pdt-category-select search-space”id =“brands”name =“brands”&gt;
&lt; option&gt; All&lt; / option&gt;
&lt;?php foreach($ posts as $ post){
echo'&lt; option value =“',$ post-&gt; post_name,'”',$ selected == $ post-&gt; ID? 'selected =“selected”':'','&gt;',$ post-&gt; post_title,'&lt; / option&gt;';
}?&gt;
&lt; / select&gt;
code> pre>
div>
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>