-1

I want to create blog content with below detail. My page:

  • Home
  • Page A
  • Page B

Blog post:

  • Post 1
  • Post 2

When creating Post 1 I want it to be showed on Page A and Post 2 to Page B How can I do that? (with code or plugin)

put on hold as unclear what you're asking by Andy Macaulay-Brook, Pat J, rudtek, Nathan Johnson, Jacob Peattie 23 hours ago

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    What have you already tried? – Max Yudin Mar 14 at 15:15
0

Make two post categories and give each post a category. Then write a function like this into your functions.php in your (child)theme folder:

function show_ony_some_on_sepcial_pages( $query ) {
    if ( get_the_ID() == 2 /* page id of page a */ && $query->is_main_query() ) {
        $query->set( 'cat', 1 /* id of category for this page */ );
    }
    if ( get_the_ID() == 3 /* page id of page a */ && $query->is_main_query() ) {
        $query->set( 'cat', 2 /* id of category for this page */);
    }
}
add_action( 'pre_get_posts', 'show_ony_some_on_sepcial_pages' );
New contributor
Bastian Haustein is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • I want specific page will show when the specific post clicked. Actually, I tried the code but it didnt work function show_ony_some_on_sepcial_pages( $query ) { if ( get_cat_ID() == 2 /* page id of category a / && $query->is_main_query() ) { $query->set( 'page_id', 1 / id of page for this post */ ); } } add_action( 'pre_get_posts', 'show_ony_some_on_sepcial_pages' ); – Viet T Mar 15 at 6:31
  • @VietT Did you remember to change all the ID numbers with the correct ones on your current installation before applying the function? Because your page A might not actually have the ID 2... – jsmod Mar 15 at 7:12
  • yep. I changed correctly. get page'ID by seeing their URL – Viet T Mar 15 at 9:25
0

Another way of doing this (without coding):

  1. Create two categories. (For example: News and Reviews...)
  2. Assign a category to each post. (Post 1 categorized as News, Post 2 as Reviews)
  3. In your theme menu/navigation simply create links to those category pages (News and Reviews) so that your final menu shows:
    • Home
    • News
    • Reviews

Each category page will automatically list all posts assigned to them. The News category page will only list posts categorized as "News".

If you are interested in taking this further, you could also create custom category page templates for each category in your theme (such as category-news.php and category-reviews.php). This will allow you to give each page a custom or unique look.

  • hi, I meant when user click post 1 --> navigate to page A (custom template) and post 2 --> navigate to page B (another template) . I tried using pre_get_posts filter but when i do $query->set('pagename', 'target-name'). it didn't work – Viet T Mar 15 at 6:30
  • hi, I meant when user click post 1 --> navigate to page A (custom template) and post 2 --> navigate to page B (another template) . I tried using pre_get_posts filter but when i do $query->set('pagename', 'target-name'). it didn't work – Viet T Mar 15 at 6:30
  • @VietT In this case, will page A show the contents of post 1 or will it have completely different content? – jsmod Mar 15 at 7:08
  • it will show the contents of post 1. In your mention below, I want all posts of category 'reviews' have their own page (with special template), different from other posts – Viet T Mar 15 at 9:24
  • If page A = post 1, then why not publish the content of post 1 as a page instead of a post? – jsmod 2 days ago

Not the answer you're looking for? Browse other questions tagged or ask your own question.