Support » Themes and Templates » Exclude 1 post by ID or NAME from Category.php

  • Inspired Media

    (@inspired-media)


    Hi All,

    I’ve got a single post that I want to remove from a specific category on category.php.

    Current code is:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <li><a>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    		<!--/post -->
    
    	<?php endwhile; endif; ?>

    [Please post code or markup snippets between backticks or use the code button.]

    I’ve searched the net for a few days, but could not find the right answer for this. Anyone who can help me out?

    Thanks alot in advance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • esmi

    (@esmi)

    Inspired Media

    (@inspired-media)

    Esmi, thanks for linking. I checked that page, but it didn’t actually help as it’s talking about excluding categories instead of posts.

    esmi

    (@esmi)

    Not quite. You can use any of the parameters described on http://codex.wordpress.org/Class_Reference/WP_Query in query_posts.

    Inspired Media

    (@inspired-media)

    Esmi, since I’m not a php programmer, could you solve the mystery for me?

    I know the post has 3 as an id, that’s about it…

    esmi

    (@esmi)

    <?php
    if( is_category( 'category-slug') :
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	''post__not_in' => array( 3 ),
    	'paged' => $paged
    );
    query_posts($args);
    endif;?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    [...]
    Inspired Media

    (@inspired-media)

    Parse error: syntax error, unexpected ‘:’ in is what i’m getting

    esmi

    (@esmi)

    Typo – missing ). Try:

    <?php
    if( is_category( 'category-slug') ) :
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	''post__not_in' => array( 3 ),
    	'paged' => $paged
    );
    query_posts($args);
    endif;?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    [...]
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Exclude 1 post by ID or NAME from Category.php’ is closed to new replies.