开发者

Wordpress - Latest blog post feed showing drafts

Here is the code I'm using to collect the posts:

$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>',
                           开发者_JAVA技巧 $Pages);
echo $Pages;

unset($Pages, $InnerPages);

Is there anyway to adapt the above to show only the published posts and exclude the draft posts?


You can use get_posts() for that:

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

snippet above is taken from codex.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜