• I would like to know if it is possible to have two articles on a post page. What I mean is, if i have a category post page of lets say saving money, and the article appears on that page, i would then like another article underneath that article from a category for example investment ideas, and for the full article to show. So basically having to articles appear on the same page. However, on that post page, the second article would be the latest article from that category, so the post page would be refreshed all the time with new content. is this possible. he is a kind of example that i found:

    • This topic was modified 8 months, 3 weeks ago by James Huff. Reason: link moved to proper field

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You can. The exact solution depends on whether your theme is a classic or block theme.

    Essentially, the single post’s template code needs to get the current post’s category and make a query for the latest post in that category. Then output the returned post in a manner similar to the main post. Add code to only do so if the current post is not the latest in the category, otherwise we’ll see the second is a duplicate of the first.

    Thread Starter websitefix

    (@websitefix)

    i am using a tagdiv template. what i want is to choose a different category to the main category on the page.

    Moderator bcworkz

    (@bcworkz)

    Are your theme’s template files .php or .html?

    You can get all category terms that are assigned to a particular post. If there are multiple terms assigned, how would code know which to use? Or should the query get the latest post having any (or all) of the terms? It’s possible to exclude the archive query’s category from this logic, but what if the archive’s term is the same as the only term assigned to the post? Your code would need a special condition to manage such a situation.

    Get all category terms assigned to a post with wp_get_post_categories(). Once you have the appropriate terms, use get_posts() to get the latest post fitting your desired criteria.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘can i have two articles on a post page’ is closed to new replies.