0
votes

I'm trying to build a datablog that is about what happens on my blog. I don't want these posts to appear on the front page, so I want to exclude the category they're in, as they're always in the same category.

Can you help me?

The site is denfri.dk, I'm using snap theme (https://thethemefoundry.com/wordpress-themes/snap/) and my loop code looks like 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! It looks like you haven\'t added any posts yet. <a href="%s" title="Add post">Add your first post</a> now!',
                    'snap'
                ),
                esc_url( admin_url( 'post-new.php' ) )
            );
        ?>
    </p>
</div>

1
you want to add exclude categroy id in functions.php category array . And Create new fucntion to display post excluded array. - kuldip Makadiya

1 Answers

0
votes

To include one (or more) categories from your frontpage insert this 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 you want to exclude more categories than just one, replace -5 with all categories separated with commas; -5,-1,-3 etc.