WordPress.org

Ready to get started?Download WordPress

Forums

Exclude 1 post by ID or NAME from Category.php (8 posts)

  1. Inspired Media
    Member
    Posted 2 years ago #

    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!

  2. esmi
    Forum Moderator
    Posted 2 years ago #

  3. Inspired Media
    Member
    Posted 2 years ago #

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

  4. esmi
    Forum Moderator
    Posted 2 years ago #

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

  5. Inspired Media
    Member
    Posted 2 years ago #

    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...

  6. esmi
    Forum Moderator
    Posted 2 years ago #

    <?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(); ?>
    [...]
  7. Inspired Media
    Member
    Posted 2 years ago #

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

  8. esmi
    Forum Moderator
    Posted 2 years ago #

    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(); ?>
    [...]

Topic Closed

This topic has been closed to new replies.

About this Topic