WordPress.org

Forums

How to Configure? Posts with tag "x" to not appear on main blog page (4 posts)

  1. kimmer01
    Member
    Posted 2 years ago #

    I want some posts to only appear on a secondary page.

    I am using "Posts for Page Plugin" and have it configured the way I want. Posts with tag "x" are going to a secondary page (http://rippere.com/kakidesign/).

    I would like for the posts that are going to this secondary page to *not* also appear on the main blog page (http://rippere.com/my-voice/).

    Any help would be appreciated!

  2. Dandy Plow
    Member
    Posted 2 years ago #

    On the main blog page, find this:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    blah blah blah
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    and replace it with this:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php
    $blockit = "no";
    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
        if($tag->name=="x") {
    $blockit = "yes";
    }
    }
    }
    ?>
    
    <?php if($blockit=="no") { ?>
    
    blah blah blah
    
    <?php }; ?>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
  3. kimmer01
    Member
    Posted 2 years ago #

    Wow! And if I wanted an easier answer with no coding?!? ;/

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    function voodoo_exclude_tag( $query ) {
         if( $query->is_main_query() && $query->is_home() ) {
              $query->set( 'tag_id', '-4' );
         }
    }
    
    add_action( 'pre_get_posts', 'voodoo_exclude_tag' );

    There might be a plugin to modify what's displayed on the homepage. Not sure...

    Here's another code example... that might be a bit easier to implement. You would need to adjust the -4 to your tag ID, which can be found on the admin side by looking at the url presented for that particular tag (in the tags admin menu, usually found by hovering on the tag title). Fo rinstance:

    http://domain.com/wp-admin/edit-tags.php?action=edit&taxonomy=post_tag&tag_ID=39&post_type=post

    The tag ID here is 39

    So, to exclude it in the above query we use -39

    This little bit of code can just go into functions.php in the theme

    You could also keep looking for a plugin, of course! I just don't know of any offhand...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags