the_content(); doesn't print anything in my wordpress custom template page
I have to show 2 articles in a custom template page in my wordpress blog, but this code show nothing.
$myposts = get_posts("numberposts=2&category=3");
foreach($myposts as $post) : the开发者_如何学编程_content(); endforeach;
but if I try to print_r($myposts);
I can say that there is an array..how can i solve this problem?
thanks a lot
Write this line:
the_post();
before you use:
the_content();
Ya need to use the loop!
query_posts("numberposts=2&category=3");
while ( have_posts() ): the_post();
the_content();
endwhile;
can you try with this:-
<ul>
<?php
global $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 the_content() ?>
<?php endforeach; ?>
</ul>
may helpful http://codex.wordpress.org/Template_Tags/get_posts Thanks.
精彩评论