如何根据作者/用户slug显示数据

时间:2016-03-23 12:16:46

标签: php wordpress

我正在创建一个会员网站,允许其他会员查看其他用户个人资料。每个用户都可以添加帖子(我已经做过),但问题是根据用户显示帖子。

<?php
    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
    $author_query = array('post_type' => 'articles', 'posts_per_page' => '-1', 'author' => $curauth->ID);
    $author_posts = new WP_Query($author_query);
    while ($author_posts->have_posts()) : $author_posts->the_post();
        ?>

        <li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                <?php the_title(); ?>
            </a>
        </li><br/>
        <?php
        if (has_post_thumbnail()) :
            the_post_thumbnail('medium');
        endif;
    endwhile;
?>

它会发生什么,它只显示当前登录用户的帖子,但我希望它发生的是显示该公开的成员的文章和他们发布的帖子。 例如

domain.com/pedro

 Article 1

 Article 2

domain.com/felipe

Article 3

Article 4

1 个答案:

答案 0 :(得分:0)

在主题中添加author.php页面(如果已存在则忽略)。

然后你的网址会是这样的 http://example.com/author/hallmark/

其中hallmark是用户名,此页面(author.php)已经拥有获取特定用户帖子的代码。

您可以将作者网址设为<a href="<?php echo site_url().'/?author='.USERID;?>" > See all Posts of this Author </a>

相关问题