• I have this code:

    /**
    	 * Display Latest posts
    	 */
    	static function showLatest( $posts = 5, $size = 45 ) {
    		global $post;
    		$latest = get_posts( array( 'suppress_filters' => false, 'ignore_sticky_posts' => 1, 'orderby' => 'post_date', 'order' => 'desc', 'numberposts' => $posts ) );
    
    		ob_start();
    		$count = 1;
    		$date_format = get_option('date_format');
    		foreach($latest as $post) :
    			setup_postdata($post);
    			if( $count++ % 2 ){
    				$class = 'odd';
    			} else {
    				$class = 'even';
    			}
    		?>
    			<li class="<?php echo $class; ?>">
    				<?php if ($size <> 0){
    					$imageArgs = array(
    						'width' => $size,
    						'height' => $size,
    						'image_class' => 'thumbnail',
    						'format' => 'array',
    						'default_image' => self::getWidgetUrl() . 'default.png'
    					);
    					$postImage = pptwj_get_the_image($imageArgs);
    				}
    				?>
    				<?php if( !empty( $postImage['src'] ) ):
    					$css = "width: {$size}px; height: {$size}px;";
    				?>
    				<a class="post-thumb" href="<?php the_permalink(); ?>"><img src="<?php echo $postImage['src']; ?>" alt="<?php echo $postImage['alt']; ?>" width="<?php echo $postImage['width']; ?>" height="<?php echo $postImage['height']; ?>" style="<?php echo $css; ?>"/></a>
    				<?php endif; ?>
    
    				<a class="item-title" title="<?php the_title_attribute(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    
    				<?php echo self::item_meta(get_the_time($date_format, $post)); ?>
    
    				<div class="fix"></div>
    			</li>
    		<?php endforeach;
    		$contents = ob_get_contents();
    		ob_end_clean();
    		return $contents;
    	}

    I am trying to make that to display all the articles excepting a category with id 12. Do you know where do i have to add something in my code ?

    Thanks for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • add the exclude into this line:

    $latest = get_posts( array( 'suppress_filters' => false, 'ignore_sticky_posts' => 1, 'orderby' => 'post_date', 'order' => 'desc', 'numberposts' => $posts ) );

    for example:

    $latest = get_posts( array( 'suppress_filters' => false, 'ignore_sticky_posts' => 1, 'orderby' => 'post_date', 'order' => 'desc', 'numberposts' => $posts, 'category__not_in' => array( 12 ) ) );

    https://codex.www.ads-software.com/Class_Reference/WP_Query#Category_Parameters

    Thread Starter LiviutzuAs

    (@liviutzuas)

    Thanks very very much. I tryied to edit that line until now but no success until u told me ‘category__not_in’ => array( 12 ) !

    Thanks very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘CODE – Except category’ is closed to new replies.