WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do I best exclude a category from home page (6 posts)

  1. bobmorris60
    Member
    Posted 1 year ago #

    I would like to exclude category 6 from displaying on the home page.

    I found this code in the Codex but it also indicated this might not be the best way to do it.

    <?php
    if ( is_home() ) {
    	query_posts( 'cat=-6' );
    }
    ?>

    I'm also not quite sure where the code would go in index.php. The blog uses the Atuahalpa theme. Here's index.php for Atahualpa. Any help appreciated.

    <?php
    list($bfa_ata, $cols, $left_col, $left_col2, $right_col, $right_col2, $bfa_ata['h_blogtitle'], $bfa_ata['h_posttitle']) = bfa_get_options();
    get_header();
    extract($bfa_ata);
    global $bfa_ata_postcount;
    ?>
    
    <?php /* If there are any posts: */
    if (have_posts()) : $bfa_ata_postcount = 0; /* Postcount needed for option "XX first posts full posts, rest excerpts" */ ?>
    
    	<?php // Deactivated since 3.6.5
    	# include 'bfa://content_above_loop';
    	// Uses the following static code instead: ?>
    	<?php bfa_next_previous_page_links('Top'); // For MULTI post pages if activated at ATO -> Next/Previous Navigation:  ?>
    
    	<?php while (have_posts()) : the_post(); $bfa_ata_postcount++; ?>
    
    		<?php // Deactivated since 3.6.5
    		#include 'bfa://content_inside_loop';
    		// Uses the following static code instead: ?>
    		<?php bfa_next_previous_post_links('Top'); // For SINGLE post pages if activated at ATO -> Next/Previous Navigation  ?>
    		<?php /* Post Container starts here */
    		if ( function_exists('post_class') ) { ?>
    		<div <?php if ( is_page() ) { post_class('post'); } else { post_class(); } ?> id="post-<?php the_ID(); ?>">
    		<?php } else { ?>
    		<div class="<?php echo ( is_page() ? 'page ' : '' ) . 'post" id="post-'; the_ID(); ?>">
    		<?php } ?>
    		<?php bfa_post_kicker('<div class="post-kicker">','</div>'); ?>
    		<?php bfa_post_headline('<div class="post-headline">','</div>'); ?>
    		<?php bfa_post_byline('<div class="post-byline">','</div>'); ?>
    		<?php bfa_post_bodycopy('<div class="post-bodycopy clearfix">','</div>'); ?>
    		<?php bfa_post_pagination('<p class="post-pagination"><strong>'.__('Pages:','atahualpa').'</strong>','</p>'); ?>
    		<?php bfa_archives_page('<div class="archives-page">','</div>'); // Archives Pages. Displayed on a specific static page, if configured at ATO -> Archives Pages: ?>
    		<?php bfa_post_footer('<div class="post-footer">','</div>'); ?>
    		</div><!-- / Post -->	
    
    	<?php endwhile; ?>
    
    	<?php // Deactivated since 3.6.5
    	# include 'bfa://content_below_loop';
    	// Uses the following static code instead: ?>
    	<?php bfa_next_previous_post_links('Middle'); // Displayed on SINGLE post pages if activated at ATO -> Next/Previous Navigation: ?>
    	<?php bfa_get_comments(); // Load Comments template (on single post pages, and static pages, if set on options page): ?>
    	<?php bfa_next_previous_post_links('Bottom'); // Displayed on SINGLE post pages if activated at ATO -> Next/Previous Navigation: ?>
    	<?php bfa_next_previous_page_links('Bottom'); // Displayed on MULTI post pages if activated at ATO -> Next/Previous Navigation: ?>
    
    <?php /* END of: If there are any posts */
    else : /* If there are no posts: */ ?>
    
    <?php // Deactivated since 3.6.5
    #include 'bfa://content_not_found';
    // Uses the following static code instead: ?>
    <h2><?php _e('Not Found','atahualpa'); ?></h2>
    <p><?php _e("Sorry, but you are looking for something that isn't here.","atahualpa"); ?></p>
    
    <?php endif; /* END of: If there are no posts */ ?>
    
    <?php get_footer(); ?>
  2. ChiefWigs1982
    Member
    Posted 1 year ago #

    I use a plugin called "Advanced Category Excluder" which allows me to choose where my categories appear.

    It lets you control all sorts of things: whether the particular categories appear in the sidebar, on the home page, etc.

    Plus, you don't need to edit any code, so you should have less trouble when it comes to upgrading. :)

    Cheers,

    --Jon.

  3. bobmorris60
    Member
    Posted 1 year ago #

    That worked. Thank you!

    Yes, not having to put code back in after upgrading in a good thing.

  4. janjan32
    Member
    Posted 1 year ago #

    I need to display different categories on different pages.
    My code looks like this:

    <!-- show just the one category id 4-->
    
    <?php if (have_posts()) : ?>
    
    	<?php while (have_posts()) : the_post(); ?>
    
    		<div <?php post_class('clearfix excerpts') ?> id="post-<?php the_ID(); ?>">
    
    			<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    
     <?php the_post_thumbnail( 'image-220', array('class'=> 'rounded-corners')); ?>		<?php the_excerpt(); ?>
    
    		</div> <!--end of post class-->

    and I only want to display cat 4. Any ideas where I would add code to make this work? Thanks for any advise.

  5. janjan32
    Member
    Posted 1 year ago #

    for the record I added
    <?php query_posts('cat=4');?>
    above the loop and below it and it still didn't work... I've done this before, just can't seem to get it to work with this template.

    Thanks for any help...

  6. nothroughroad
    Member
    Posted 1 year ago #

    janjan32 try adding cat4 as a menu item. Does that do what you want?

Topic Closed

This topic has been closed to new replies.

About this Topic