• Could anyone help me in excluding a category in the grid from the home page?

    I have single items only showing the same category when they’re selected but can’t see where i should add ‘exclude’ within the PHP for the index page.
    Normally this wouldn’t be a problem to achieve but this theme is structured quite differently to those I’ve used before.

Viewing 4 replies - 1 through 4 (of 4 total)
  • vtxyzzy

    (@vtxyzzy)

    Impossible to say without a link to your site and access to the theme index.php.

    Thread Starter ecooke

    (@ecooke)

    homepage is http://www.stemdesign.co.uk/site

    index php is the following:

    <?php get_header(); 	// [grid column setting]
    	$col_w = 290; // width of grid column
    	$gap_w = 35;  // padding + margin-right (15+15+5)
    	$max_col = 2; // max column size (style div.x1 ~ xN)
    
    	// * additional info *
    	// check also "style.css" and "header.php" if you change $col_w and $gap_w.
    	// - style.css:
    	//   div.x1 ~ xN
    	//   div.grid-item
    	//   div.single-item
    	//   ... and maybe #sidebar2 li.widget.
    	// - header.php:
    	//   gridDefWidth in javascript code.
    	//
    	// if you want to show small images in main page always, set $max_col = 1.
    
    	// [grid image link setting]
    	$flg_img_forcelink = true;   // add/overwrite a link which links to a single post (permalink).
    	$flg_img_extract = true;    // in single post page, extract thumbnail link to an original image.
    	$flg_obj_fit = 'large-fit';  // none | small-fit | large-fit ... how to fit size of object tag.
    	$max_col = 1
    	// * additional info *
    	// if you use image popup utility (like Lightbox) on main index, set $flg_img_forcelink = false;
    ?>
    
    <?php if (is_singular()) : $is_top_single = true; /* wide column for single post */ ?>
    
    	<div id="single-wrapper">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    		<div <?php post_class('single-item'); ?> id="post-<?php the_ID(); ?>">
    			<h2 class="post-title"><?php the_title(); ?></h2>
    
    			<div class="post-body">
    
    <?php
    					if ($flg_img_extract) {
    						$content = get_the_content();
    						$content = apply_filters('the_content', $content);
    						$content = adjust_single_image($content);
    						echo $content;
    					}
    					else {
    						the_content();
    					}
    
    				?>
    
    			</div>
    			<?php wp_link_pages('before=<p class="pagination" id="post-pagination"><span class="prefix">' . __('Pages:') . '</span>'); ?>
    
    <?php endwhile; else : ?>
    
    		<div class="single-item">
    			<h2>Not Found</h2>
    			<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    		</div>
    
    <?php endif; ?>
    
    	</div></div><!-- /single-wrapper -->
    
    <?php /* make a new query for grid items (in single page) */
    	$arr_catID = array('');
    	foreach( get_the_category() as $cat) $arr_catID[] = $cat->cat_ID;
    	if ( count($arr_catID) ) $new_query_arg .= '&cat=' . join(',', $arr_catID);
    
    ?>
    
    <?php endif; /* end of if is_singular() */ ?>
    
    <?php get_sidebar(); ?>
    
    	<div id="grid-wrapper">
    
    <?php if (have_posts()) :
    	if ( $is_top_single ) $GLOBALS['more'] = false; //important
    	while (have_posts()) : the_post(); ?>
    <?php
    	$content = get_the_content('');
    	$content = apply_filters('the_content', $content);
    	list($col_class, $grid_img) = adjust_grid_image(
    		$content,
    		$col_w,
    		$gap_w,
    		$max_col,
    		$flg_img_forcelink,
    		$flg_obj_fit
    	);
    ?>
    
    		<div <?php post_class('grid-item ' . $col_class); ?> id="post-<?php the_ID(); ?>">
    		            <h1 class="post-title"><?php the_title(); ?></h1>			
    
    <div class="grid-body">
    <?php
    	$content = preg_replace('/<img(?:[^>]+?)>/', '', $content); // remove img tags
    	$content = preg_replace('/<a([^>]+?)><\/a>/', '', $content); // remove empty a tags
    	$content = preg_replace('/<p([^>]*?)><\/p>/', '', $content); // remove empty p tags
    	$content = preg_replace('/<object(.+?)<\/object>/', '', $content); // remove object tags
    	echo $content;
    ?>
    			</div>
    
    	<?php if ($grid_img) echo '<div class="grid-image">' . $grid_img . '</div>'; ?>
    
    		</div>
    
    <?php endwhile; else : ?>
    
    		<div class="grid-item x1">
    			<h2>Not Found</h2>
    			<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    		</div>
    
    <?php endif; ?>
    
    	</div><!-- /grid-wrapper -->
    
    	<div class="pagination" id="grid-pagination">
    		<?php paginate_links2($is_top_single); ?>
    	</div>
    
    <?php /* reset the query */
    	wp_reset_query();
    ?>
    
    <?php get_sidebar('2'); ?>
    
    </div><!-- /container -->
    
    <?php get_footer(); ?>

    I basically don’t want anything from the info category showing up on the home page (cat ID 2) I’ve tried every everything I can think of using code from the codex support & various google searches with no luck!

    Shane G.

    (@shane-g-1)

    Hi,

    Check with this plugin:

    http://wordpress.org/extend/plugins/advanced-category-excluder/

    Thanks,

    Shane G.

    Add this to your function page:

    function exclude_category($query) { if ( $query->is_home ) { $query->set(‘cat’, ‘-1 -2 -3’); } return $query; }
    add_filter(‘pre_get_posts’, ‘exclude_category’);

    // -1 ecc. stay for the category number to exclude

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude category on the home page’ is closed to new replies.