Site logo

Archived topic

Exclude a category in Home Blog

3 replies · Started by Olivier on July 11, 2018

Viewing posts 1–4 of 4

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' );
			?>

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

No problem!

This archived topic is closed to new replies.