• Resolved vleavell

    (@vleavell)


    Hello,

    I am new to the WP scene, but love it! I have a site https://www.nationalrepublicrat.com. I would like all posts from category 20, Videos, not to be displayed in the main body or content section. I have them setup in my sidebar and only want it there.

    How can I remove the category from showing?

    Here is my index.php:

    <?php get_header(); global $wp_theme_options; ?>
    <?php do_action('before_content'); ?>
    
    <!--index.php-->
    <div class="<?php do_action('content_style'); ?>" id="content">
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); // the loop ?>
    
    	<!--Post Wrapper Class-->
    	<div <?php if (function_exists('post_class')) { post_class(); } else { echo 'class="post"'; } ?>>
    
    	<!--Title/Date/Meta-->
    	<div class="title wrap">
    		<div class="date">
    			<div class="month"><?php the_time('M'); ?></div>
    			<div class="day"><?php the_time('d'); ?></div>
    		</div>
    		<div class="post-title">
    			<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
    			By
    			<span class="meta-author"><?php the_author_posts_link(); ?></span>
    			 &middot;  Comments
    			<span class="meta-comments"><?php comments_popup_link('(0)', '(1)', '(%)'); ?></span>
    		</div>
    	</div>
    
    	<!--post text with the read more link-->
    	<?php the_content('Read More&rarr;'); ?>
    
    	<!--post meta info-->
    	<div class="meta-bottom wrap">
    		<div class="alignleft"><span class="categories">Categories : <?php the_category(', ') ?></span></div>
    		<div class="alignright"><span class="comments">Comments <?php comments_popup_link('(0)', '(1)', '(%)'); ?></span></div>
    	</div>
    
    	</div><!--end .post-->
    
    	<?php endwhile; // end of one post ?>
    
        <!-- Previous/Next page navigation -->
        <div class="paging clearfix">
    	    <div class="alignleft"><?php previous_posts_link('&laquo; Previous Page') ?></div>
    	    <div class="alignright"><?php next_posts_link('Next Page &raquo;') ?></div>
        </div>    
    
    	<?php else : // do not delete ?>
    
    	<div class="post">
    	<h3><?php _e("Page not Found"); ?></h3>
        <p><?php _e("We're sorry, but the page you're looking for isn't here."); ?></p>
        <p><?php _e("Try searching for the page you are looking for or using the navigation in the header or sidebar"); ?></p>
        </div>
    
    	<?php endif; // do not delete ?>
    
    </div><!--end #content-->
    
    <?php do_action('after_content'); ?>
    <?php get_footer(); //Include the Footer ?>

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The Loop talks about excluding categories.

    But also could use this query_posts() construct before your if (have_posts()) logic:

    query_posts ($query_string . '&cat=-20)

    You should be able to remove it using an if condition to spot out post with that category ID and skip it and move on to the next. I’d post an exact solution, but I don’t have to time. Hope this helps anyway.

    Thread Starter vleavell

    (@vleavell)

    Hi MichaelH,

    Thanks for the reply! I used the query_post as follows, but it is still displaying the posts. Did I put it in the wrong location?

    <!--index.php-->
    <div class="<?php do_action('content_style'); ?>" id="content">
            query_posts ($query_string . '&cat=-20)
    	<?php if (have_posts()) : while (have_posts()) : the_post(); // the loop ?>

    Thanks!

    Oops, forgot a closing ‘

    query_posts ($query_string . '&cat=-20')

    Thread Starter vleavell

    (@vleavell)

    Unfortunately no go. Now it just shows the code on the screen right before the post. Am I putting the code in the correct place?

    <!--index.php-->
    <div class="<?php do_action('content_style'); ?>" id="content">
            query_posts ($query_string . '&cat=-20')
    	<?php if (have_posts()) : while (have_posts()) : the_post(); // the loop ?>

    Thanks!

    Missed that – have to enclose php code with correct tags

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

    Thread Starter vleavell

    (@vleavell)

    Awesome! That did the trick!

    Thank you very much!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How Eliminate a Specific Category From Displaying in the Main Page Content’ is closed to new replies.