WordPress.org

Forums

Altering the loop to show different templates on specific posts (8 posts)

  1. rob_870
    Member
    Posted 1 year ago #

    Hi
    I wondered if anyone could help me regarding the loop. I'm displaying custom meta on posts and in the excerpt (see below). However there are some posts in particular categories where I dont want this to show. Can I put a conditional query at all in the loop?

    Thankyou very much in advance

    See loop below, the example page is
    http://www.muddyrace.co.uk/south-east/warrior-adrenaline-race-bedfordshire/. The

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. rob_870
    Member
    Posted 1 year ago #


  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    there are conditional tags, in your case possibly in_category()

    http://codex.wordpress.org/Conditional_Tags

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

  4. rob_870
    Member
    Posted 1 year ago #

    great thanks, i thought so much.

    There is only one or two categories where i dont want them to show on posts. Is there a way of using this conditional tag, but stating:

    If in a certain category do NOT show rather than do show? As there's quie a few categories on the site?

    Also where would this go in the following line of code?
    <div class="meta"><b>Region: </b><?php $key="Region"; echo get_post_meta($post->ID, $key, true); ?></div>

  5. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try:

    <?php if( !in_category('certain') ) { ?>
    <div class="meta"><b>Region: </b><?php $key="Region"; echo get_post_meta($post->ID, $key, true); ?></div>
    <?php } ?>

    clear text: if NOT in_category then show 'region'

  6. rob_870
    Member
    Posted 1 year ago #

    works a treat - thank you so much for your time.

  7. rob_870
    Member
    Posted 1 year ago #

    one more thing if i wanted to exclude from 2 categories would it be just ('certain', 'certain1') for example?

    thanks

  8. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    for multiple categories, please fully read the quoted Codex chapter: http://codex.wordpress.org/Function_Reference/in_category

Topic Closed

This topic has been closed to new replies.

About this Topic