WordPress.org

Ready to get started?Download WordPress

Forums

Loop & Filters with Tags (3 posts)

  1. DanielDiggle
    Member
    Posted 6 years ago #

    Hiya, I'm looking for some advice on how to proceed with a site I'm developing.

    Live Preview:
    Graphic Preview:

    My question; is it the best way to loop through the 4 content sections each time and then filter it to show specifically tagged content and then re-set, or can wordpress actively 'get' specific tagged content for each section. I wasn't entirely sure on which way to proceed.

    A brief description of what I'm trying to achieve overall is below.

    On the main page will be 4 different groups of content, I want to separate this content using tag's rather that categories.

    1/.Latest content tagged with 'content1'
    2/.Main feed, all content tagged with 'content2'-(with pagination)
    3/.Latest content tagged with 'content3'
    5/.Latest 5 items tagged with 'content4'

    The aim is that the main feed [2.] will initially show only content tagged 'content2' but if the latest item in any of the other 3 sections is clicked, it will replace that tagged content into the main feed.

    Does this sound possible?
    Any help or advice is great, thanks.

  2. scribblerguy
    Member
    Posted 6 years ago #

    The first part of what you want to do (the four loops) is definitely doable. Take a look at the multiple loop examples on the Codex page for
    The Loop.

    To only get certain posts, use the query_posts() function before a loop. E.g. --

    <?php query_posts('tag=content1&limit=10'); ?>

    Depending on what you're doing, you may need to use the rewind_posts() function to reset the main page's default (or implicit) query before using the query_posts() function.

    One caveat: Make sure your loops work correctly on the "Older Entries" pages, as the "pages" that those older entries will be on are going to have a different default query. If the query calls aren't constructed right, the non-main loops may show older posts rather than the newest posts for that loop.

    The aim is that the main feed [2.] will initially show only content tagged 'content2' but if the latest item in any of the other 3 sections is clicked, it will replace that tagged content into the main feed.

    Take a look at the Template Hierarchy page in the Codex. To best accomplish what (I think that) you want to do, is to separate out the code for your left column and right column and save those to separate files that you can include. (If you haven't done that already.)

    If you name those files sidebar-left.php and sidebar-right.php, you can use the WP function sidebar(); to include the file contents. E.g. <?php sidebar('left'); ?>

    When a user clicks on the link for a post, WP will display that individual post using the single.php template file. To make sure that an individual post page works correctly, given all your multiple loops, you should follow the "Multiple Loops Example 2" from the Codex page about "The Loop." The same should apply to other pages (categories, archives, tags, etc.).

    Hope that explanation helps. Using multiple loops isn't too tricky, but it does have potential pitfalls.

  3. DanielDiggle
    Member
    Posted 6 years ago #

    Thanks for the help! All the elements are already seperate, side-bars etc. So it's halfway there! I'll read up again on the loop.

    cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic