以下是我用来收集帖子的代码:
$Pages = wp_list_pages('title_li=&echo=0&depth=1&exclude=39,190');
$InnerPages = wp_list_pages('child_of='.($post->post_parent != false ? $post->post_parent : $post->ID).'&title_li=&echo=0');
$Title = ($post->post_parent != false) ? trim(get_the_title($post->post_parent)) : trim(wp_title('', false));
if($Title != '')
$Pages = str_replace($Title.'</a></li>',
$Title.'</a>'.
'<ul>'.$InnerPages.'</ul></li>',
$Pages);
echo $Pages;
unset($Pages, $InnerPages);
是否有适应上述内容仅显示已发布的帖子并排除草稿帖子?
答案 0 :(得分:1)
您可以使用get_posts():
<ul>
<?php
global $post;
$tmp_post = $post;
$myposts = get_posts('numberposts=5&offset=1&category=1');
foreach($myposts as $post) :
setup_postdata($post);
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
<?php $post = $tmp_post; ?>
</ul>
上面的代码段取自codex。