如何在wordpress中获得作者的第一篇文章

问题描述:

如何获得特定作者最近的帖子和帖子描述?如何在wordpress中获得作者的第一篇文章

任何人都可以帮助我吗?

在此先感谢。

获取作者ID,并且做这样的事情:

$args = array(
    'author' => $AUTHOR_ID, // Set this value! 
     'showposts' => 1, 
     'caller_get_posts' => 1 
    ); 
$query = new WP_Query($args); 
if($query->have_posts()) { 
    while ($query->have_posts()) : $query->the_post(); ?> 
     <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> 
     <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?> </small> 
     <?php the_content(); 
    endwhile; 
} 
+0

哇..完美的作品!感谢好友......并且我有另一个疑问。是否有任何选项来限制[更多...]的内容?如果你知道分享我的乐趣...... – 2011-03-31 15:35:18

要获得在主回路中的任何职位你使用

query_posts(//Parameters); 

如果你想创建一个二次回路,可以用你希望的任何参数创建WP_Query的新实例,如下所示:

$some_variable = new QP_Query(//Your parameters go here); 

请记住,你可以无论是创建一个数组在所有的参数,如:

$args = array ('numberposts' => 5, 'offset' => 0); 
$some_variable = new WP_Query($args); 

或者你可以只是简单地通过它一直在一个字符串:

$some_variable = new WP_Query ('numberposts=5&offset=0&order=DESC'); 
//Remember to separate the parameters with an ampersand: '&' 

无论怎样,你应该选择工作;我个人更喜欢避免使用query_posts或get_posts。相反,我只需创建一个新的WP_Query对象,并在每次需要获取某些资源时将参数作为简单的字符串传递。

一些资源:

http://codex.wordpress.org/Template_Tags/get_posts 
http://codex.wordpress.org/Function_Reference/WP_Query