[Resolved] Exclude a category in Home Blog

Home Forums Support [Resolved] Exclude a category in Home Blog

Home Forums Support Exclude a category in Home Blog

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #621166
    Olivier

    Hi

    I have place this code “query_posts( ‘cat=-293’ );” in /generatepress_child/index.php to exclude just one category, it’s work but i have the last four same posts indefinitely in my home and I don’t find the solution, have you an idea ?
    Thank you 🙂

    <?php
    			/**
    			 * generate_before_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_before_main_content' );
    
    			if ( have_posts() ) :
    			
    				/* On n'affiche pas la catégorie "Salons de coiffure" N°293 en accueil du blog */
    				query_posts( 'cat=-293' );
    			
    				while ( have_posts() ) : the_post();
    
    					/* Include the Post-Format-specific template for the content.
    					 * If you want to override this in a child theme, then include a file
    					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    					 */
    					get_template_part( 'content', get_post_format() );
    
    				endwhile;
    
    				generate_content_nav( 'nav-below' );
    
    			else :
    
    				get_template_part( 'no-results', 'index' );
    
    			endif;
    
    			/**
    			 * generate_after_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_after_main_content' );
    			?>
    GeneratePress 2.1.3
    GP Premium 1.6.2
    #621290
    Leo
    Staff
    Customer Support
    #621746
    Olivier

    Hi
    Thank you.

    This is the good code to exclude one or more category :

    function exclude_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '-1,-1347' );
        }
    }
    add_action( 'pre_get_posts', 'exclude_category' );

    Have a nice day

    #622145
    Leo
    Staff
    Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.