php - Exclude specific category from loop in WordPress -
i'm trying build datablog happens on blog. don't want these posts appear on front end page, want exclude category they're in, they're in same category.
can help me?
the site denfri.dk, i'm using snap theme (https://thethemefoundry.com/wordpress-themes/snap/) , loop code looks this:
<?php if ( have_posts() ) : ?> <div class="blog-wrapper" id="content"> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( '_post-content' ); ?> <?php endwhile; ?> </div> <h1 class="hidden">denfri.dk - nyheder, analyser, satire og kritik</h1> <?php $prev = get_previous_posts_link( __( 'nyere indlæg', 'snap' ) ); ?> <?php $next = get_next_posts_link( __( 'Ældre indlæg', 'snap' ) ); ?> <?php if ( ( ! empty( $prev ) || ! empty( $next ) ) ) : ?> <nav class="pagination post-footer"> <?php if ( ! empty( $prev ) ) : ?> <div> <?php echo $prev; ?> </div> <?php endif; ?> <?php if ( ! empty( $next ) ) : ?> <div> <?php echo $next; ?> </div> <?php endif; ?> </nav> <?php endif; ?> <?php else : ?> <div class="placeholder-text"> <p> <?php printf( __( '<strong>admin:</strong> oh snap! looks haven\'t added posts yet. <a href="%s" title="add post">add first post</a> now!', 'snap' ), esc_url( admin_url( 'post-new.php' ) ) ); ?> </p> </div>
to include 1 (or more) categories frontpage insert code:
function denfri_frontpage_exclude( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-5' ); } } add_action( 'pre_get_posts', 'denfri_frontpage_exclude' );
if want exclude more categories one, replace -5
categories separated commas; -5,-1,-3
etc.
php wordpress category
No comments:
Post a Comment