WordPress.org

Ready to get started?Download WordPress

Forums

Question about has_tag condition (3 posts)

  1. supernovia
    Member
    Posted 3 years ago #

    Hi guys....

    If I use a has_tag condition on my loop, will the loop go through posts until it finds something with that tag, or will it quit looking after so many posts?

    On my loop-index.php, I want to display articles tagged "featured-article", so I've used this condition just after I start my loop:

    <?php if ( has_tag('featured-article') ) : ?>

    It worked pretty well until someone went through and added a bunch of other posts without using that tag in them.

    You can see my loop-index displaying an article with that tag, but not until eleven pages along: http://dev.renacademy.org/charter-school/page/11/

    I've tried going through the documentation and maybe I've missed something, but as far as I can tell, we should expect the loop to keep looking for that tag until it has enough posts for that page.

    By the way, I did notice a sticky post feature that probably would work as well for what we're trying to do in this instance, but we'll probably want to add other tag-conditioned loops to our index later, so I'd appreciate any ideas you have.

    Thanks in advance,

    -Velda

  2. ambrosite
    Member
    Posted 3 years ago #

    I think you would be much better off calling query_posts before the loop, so that only the posts you want to display are retrieved in the first place.

    query_posts('tag=featured-article');

    http://codex.wordpress.org/Function_Reference/query_posts

  3. supernovia
    Member
    Posted 3 years ago #

    That ought to work... thanks :)

Topic Closed

This topic has been closed to new replies.

About this Topic