登录用户的我的帖子部分

时间:2014-02-14 作者:Comphez

我想创建一个页面,只显示登录用户写的帖子,并获得一个链接(如www.example.com/AuthorPostsID)以放在菜单上。我试了两天。有人知道怎么修吗?谢谢

编辑:我尝试使用以下代码,将其放入函数中。php文件,但我不知道如何继续:

if ( is_user_logged_in() ):    
    global $current_user;
    get_currentuserinfo();
    $author_query = array(\'posts_per_page\' => \'-1\',\'author\' => $current_user->ID);
    $author_posts = new WP_Query($author_query);
    while($author_posts->have_posts()) : $author_posts->the_post();
    ?>
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>       
    <?php           
    endwhile;    
else :    
    echo "not logged in";    
endif;

1 个回复
最合适的回答,由SO网友:Jacob Rambo 整理而成

您不需要将代码放入主题函数中。这需要是一个自定义页面模板。在此处了解页面模板:

http://codex.wordpress.org/Page_Templates

您的代码是自定义循环,因此您还需要了解循环,然后使用WP\\U查询,以便下一站将在这里:

http://codex.wordpress.org/The_Loop

然后阅读本页:

http://codex.wordpress.org/Class_Reference/WP_Query

完成此操作后,您将准备实现自定义循环,以向作者显示其帖子。

在你改变会破坏WordPress的东西之前,先研究一下codex,以便更好地了解WordPress的工作原理。

然后,当你在这里提问时,你将能够更好地回答你遇到的问题,因为这里的人会更好地理解你的问题。

结束

相关推荐

Pagination and Related Posts

是否可以对嵌入在single中的以下相关POST代码使用分页。我的主题的php。 <?php // for use in the loop, list 5 post titles related to first tag on current post $tags = wp_get_post_tags($post->ID); if ($tags) { $first_tag = $