Allow only certains user posts to display on a page in Wordpress?
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.
- 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?
- Do I need a module for this?
- 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' );
精彩评论