开发者

Allow only certains user posts to display on a page in Wordpress?

开发者 https://www.devze.com 2023-04-11 17:12 出处:网络
I have two special users on my site. Let\'s call them user1 and user2. User 1 manages \"user page 1\" and user2 manages \"user page 2\". I want their posts to appear when I click on these links and on

I have two special users on my site. Let's call them user1 and user2. User 1 manages "user page 1" and user2 manages "user page 2". I want their posts to appear when I click on these links and only see their posts in Wordpress.

  1. Should I use categories for this a开发者_Go百科nd if so, how do I create a link to only show posts from a certain category?
  2. Do I need a module for this?
  3. If the answer is still not clear, how do I do this?


You can use wp_qurey() function to show posts from specific authors.

Display posts by author, using author id:

$query = new WP_Query( 'author=123' );

Display posts by author, using author 'user_nicename':

$query = new WP_Query( 'author_name=rami' );

More details here - http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters


You can use the get_author_posts_url() to create a link to a page listing a specific author's posts: http://codex.wordpress.org/Function_Reference/get_author_posts_url

The format of the link (if you just want to go ahead and test it in your browser first) will be http://www.yoursite.com/author/authorname.

Hope that helps!


Copy your index page loop and then change query from post_per_page query to this and you're done.

   $query = new WP_Query( 'author_name=rami' );
0

精彩评论

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

关注公众号