0
这是我第一次玩wordpress。我选择的主题有一个很好的静态外观,但在动态模式下看起来会消失。我跟着一些网络教程添加了我自己的功能,可以获取某个类别的帖子并在该位置进行打印。我认为它工作正常,直到我发现它弄乱了数据。这是我的第一个功能:wordpress get_posts()重叠打印的记录
$args = array('posts_per_page' => 6, 'offset'=> 0, 'category' => 6,'orderby'=>'id','order'=>'desc');
$posts = get_posts($args);
if(!empty($posts)){//yes we have posts
//loop results now
foreach($posts as $story) {
setup_postdata($story);
the_ID();
echo '<br/>'.the_title();
echo '<br/>'.the_excerpt();
}//end loop
}//
问题是the_ID和the_title()的第一个记录后alaways需要而exceprt显示的两个记录正确的值。
我在posts变量上打印了数组,它为我拥有的两个记录保存了两个不同的ID和标题。但是当我印刷时,只有冷杉正在显示。
有人在一些博客正确的做法是建议:
$title = apply_filters('the_title', $story->title);
$content = apply_filters('the_content', $story->content);
但随后的标题和内容变量是空/空。
任何想法我做错了请吗?我是新手对wordpress很抱歉。