WordPress.org

Forums

[resolved] Wants to exclude certain categories from certain pages (5 posts)

  1. wob
    Member
    Posted 6 years ago #

    Hello,

    I've been looking around for some sort of widget or hack that will let me remove exclude certain categories from certain pages. But I haven't found anything useful.

    Some help would be appreciated.
    I'm currently using Advanced Category Excluder, but that widget doesn't have the ability to hide from pages at all

  2. MichaelH
    Member
    Posted 6 years ago #

    Pages don't necessarily display posts, but it is possible your theme is designed to show posts in Pages. If that is so, with the help of the Template Hierarchy article, determine what Template is displaying your Pages, then you may need to add some code (e.g. query_posts()) to exclude categories.

    Example

    <?php
    query_posts($query_string . '&cat=-5');
    ?>

    Note the -5 says exclude category id 5.

  3. wob
    Member
    Posted 6 years ago #

    Thanks for your reply. I realize that I was a little short with the info.

    Anyway, I solved it in another way, using slayers custom widget and the widget that will let you add php straight into widgets.

  4. MichaelH
    Member
    Posted 6 years ago #

    the widget that will let you add php straight into widgets

    I'd guess you are talking about Otto's php code widget.

    Thanks for the feedback--will mark this resolved.

  5. timfurnish
    Member
    Posted 5 years ago #

    MichaelH. I'm trying to restrict my posts page from showing category 5 posts. Where do I place the code you mentioned above in the page template I made for this particular page?

    Your help is much appreciated.

    <?php
    query_posts($query_string . '&cat=-5');
    >

    My code:

    <?php
    /*
    Template Name: press
    */
    ?>
    
    <?php
    /**
     * @package WordPress
     * @subpackage Default_Theme
     */
    
    get_header(); ?>
    
    	<div id="content" class="narrowcolumn" role="main">
    
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    			</div>
    		</div>
    		<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    	</div>
    
    <?php include ('sidebar1.php'); ?>
    
    <?php get_footer(); ?>

    Thanks
    Tim

Topic Closed

This topic has been closed to new replies.

About this Topic