Post Queries

  • Unknown's avatar

    Need help with headers/footers and how they are linked to queries. My posts are divided among 2 main categories. They each have their own display/archive pages, each with their own respective header/footer. The issue is that I have a small number of posts that need to display on both pages/categories. The post lists are up with queries, which display correctly, but when visited, the multi-category posts are not displaying the correct header/footer. They are just displaying the top-level header/footer, which is confusing. How do I make these multi-category posts show the header/footer from the referring page only? I want it to be consistent, if they found the post from Category A, then I want Category A’s header and footer to display. And same with Category B. It’s only when you click on one of these multi-category posts that it becomes an issue. TIA!

  • Hi there! If you prefer to keep your site “lean” and avoid using extra plugins, you can achieve this using the native Template features in the WordPress Site Editor.

    Since WordPress cannot automatically detect which category a user just clicked from, the best manual approach is to create Custom Templates and assign them to your multi-category posts.Step 1: Create the Custom Templates

    1. Go to Appearance → Editor → Templates.
    2. Click the + (plus icon) and select Custom Template.
    3. Name it “Category A Single Post”.
    4. In this template, insert your Category A Header, the Post Content block, and your Category A Footer.
    5. Repeat this process to create a “Category B Single Post” template with the respective header and footer.

    Step 2: Assign the Template to the Post

    1. Open the specific post that belongs to both categories.
    2. In the right-hand Settings sidebar, look for the Template area.
    3. Click the current template name (usually “Single Post”) and select your newly created “Category A Single Post” template.
    4. Save the post.

    The Result:

    Even though the post is technically in both categories, it will now consistently display the Header and Footer of your choice.A Note on the “Referring Page” Logic:

    Without a plugin or custom JavaScript, it is not possible for a single URL (e.g., yoursite.com/my-post) to show two different headers based on where the user came from. If you absolutely need it to be dynamic (meaning the same post shows Header A for some people and Header B for others at the same time), that would require a plugin or a custom code snippet.

    However, for most sites, manually assigning the “Primary” brand’s template to the post using the steps above is the cleanest, most stable way to ensure your headers and footers match your content!

  • The topic ‘Post Queries’ is closed to new replies.