开发者

How to get author's first posts in wordpress

How to get particular author's recent post with post descri开发者_运维百科ption?

can anyone help me?

Thanks in advance.


Get the author id, and do something like this:

$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;
}


To get any post in the main loop you use

query_posts( //Parameters );

If you want to create a secondary loop, you could create a new instance of WP_Query with any parameters you wish, like so:

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

Remember that you can either create an array with all the parameters in, like this:

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

Or you could simply just pass it all along in a string:

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

Whichever way you choose should work; Personally I prefer to avoid using query_posts or get_posts. Instead, I simply create a new WP_Query object and pass the arguments as a simple string every time I need to fetch some resources.

Some resources:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜