我目前有一些代码可以显示页面上某个类别中所有帖子的列表,此页面位于使用wordpress构建的网站上。
我不确定如何编辑它,以便它只显示该页面上显示的帖子标题。
这是我目前的页面模板代码:
<?php
$backup = $post; //backup current object
$current = $post->ID; //current page ID
?>
<?php
global $post; //tells WordPress we want all the data related to the current post
$thisCat = get_the_category(); //variable filled with the category ID(s) for the current post
$currentCategory = $thisCat[0]->cat_ID; // variable that is filled with the first category ID from the list
$myposts = get_posts('numberposts=700&order=DESC&orderby=ID&category=' . $currentCategory . '&exclude=' . $current); //variable that makes a loop that displays two posts in decending order based on their ID numbers from the category defined in $currentCategory
foreach($myposts as $post) : //creates a loop that sets the ID value of $post to the ID value of $mypost
setup_postdata($post); //sets up the postdata (so all the content) of the new post
?>
<h2><?php echo the_title(); ?></h2>
<?php endforeach; ?>
澄清吃菜单项目作为帖子处理。
所以要清楚如果它们出现在当前正在浏览的页面上,如何才能显示某个类别的帖子列表?