0
我想要一个作者在页面的帖子列表。我用作者的帖子在每个页面都是动态的。我使用下面的代码。WordPress的帖子按作者查询
<ul>
<?php
global $post;
$args = array('posts_per_page' => 3, 'post_type'=> 'post', 'author_name' => 'ppm');
$myposts = get_posts($args);
foreach($myposts as $post) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
请看看author_name数组,我希望后期显示ppm用户。现在我要做的是动态的。我想从页面的自定义字段获取作者姓名。像
<?php $author_name = get_post_meta($post->ID, 'author_name', true); ?>
<ul>
<?php
global $post;
$args = array('posts_per_page' => 3, 'post_type'=> 'post', 'author_name' => '$author_name');
$myposts = get_posts($args);
foreach($myposts as $post) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
但是,代码不起作用。我如何从页面的自定义字段获取作者姓名?谁能帮忙?
对不起英语不好。
您无法在循环外获得'$ post-> ID'。 – bboy
看到代码http://wordpress.stackexchange.com/questions/36135/how-can-i-list-posts-by-author谢谢, –
我在循环内尝试,仍然无法正常工作。 –