Page 1 of 1

Help needed: Exclude Category in Posts Index (home)

Posted: Sun Jan 11, 2026 12:56 pm
by yukinaze
I've searched the forums, but I can't seem to find what I need. I was hoping to exclude a single category from the list of displayed posts on the homepage. Ideally, also want to display posts of that excluded category in a different section, but not necessary, since I can link out to that category's own page.

Is there a way to do this in code?

What I've seen is only separating the recent posts from the rest of the list. But not by category.

Re: Help needed: Exclude Category in Posts Index (home)

Posted: Sat Jan 17, 2026 9:32 pm
by Edi
What do you mean with "the list of displayed posts on the homepage"? You can also give a link to your website.

Re: Help needed: Exclude Category in Posts Index (home)

Posted: Sun Jan 18, 2026 5:03 am
by yukinaze
Edi wrote: Sat Jan 17, 2026 9:32 pm What do you mean with "the list of displayed posts on the homepage"? You can also give a link to your website.
The home.php has all the displayed posts regardless of category, yes? I was hoping to exclude a certain category from this list. For example, I have the categories: general, design, asides, and travel. I want to exclude posts in the asides category from this display. Is there a way to do that?

Re: Help needed: Exclude Category in Posts Index (home)

Posted: Mon Jan 19, 2026 10:56 pm
by Edi
Which theme do you use? Do you mean the mainpage and the navigation in the sidebar (plugin Categories)?

Re: Help needed: Exclude Category in Posts Index (home)

Posted: Tue Jan 20, 2026 8:17 am
by yukinaze
Oh! Sorry, I am working on my custom theme for personal use.

My index.php calls home.php this way:

Code: Select all

<?php
				// Bludit content are pages
				// But if you order the content by date
				// These pages works as posts

				// $WHERE_AM_I variable detect where the user is browsing
				// If the user is watching a particular page/post the variable takes the value "page"
				// If the user is watching the frontpage the variable takes the value "home"
				if ($WHERE_AM_I == 'page') {
				    if ($page->template() == 'custom') {
					include(THEME_DIR_PHP.'custom.php');
				    }
				    elseif ($page->template() == 'static') {
					    include(THEME_DIR_PHP.'page-static.php');
				    }
				    elseif ($page->template() == 'micro') {
					    include(THEME_DIR_PHP.'page-micro.php');
				    }
				    elseif ($page->template() == 'now') {
					    include(THEME_DIR_PHP.'page-now.php');
				    }
				    else {
					    include(THEME_DIR_PHP.'page.php');
				    }
			        } elseif ( $WHERE_AM_I === 'category' ) {
				    include( THEME_DIR_PHP.'category.php' );
			        } elseif ( $WHERE_AM_I === 'tag' ) {
				    include( THEME_DIR_PHP.'tag.php' );
			    } else {
				    include(THEME_DIR_PHP.'home.php');
			    }
			?>
And so my home.php has this:

Code: Select all

<?php 
    foreach ($content as $page) : ?>
    <?php $category = getCategory($categoryKey); ?>
    <li class="list-group-item d-flex justify-content-between align-items-center px-4 py-3<?php if ( $page->tags( true ) ): ?><?php foreach( $page->tags( true ) as $tagKey=>$tagSlug ) :?> <?php echo $tagSlug ?><?php endforeach; ?><?php endif; ?><?php if ($page->sticky()) : ?> sticky<?php endif ?>">
    <!-- Post -->
        <div class="postItem me-auto">
            <?php if ($page->sticky()) : ?><i class="fa-solid fa-thumbtack text-muted"></i><?php endif ?>
            <a class="titleLink" href="<?php echo $page->permalink(); ?>"><h4 class="title"><?php echo $page->title(); ?>  <?php if ($page->coverImage()) : ?><?php endif ?></h2></a>
            <div class="blurb"><p><?php echo $page->custom('microblogging'); ?></p></div>
            <p class="mb-0 readingTime"><small class="text-body-secondary"><?php echo $L->get('Reading time') . ': ' . $page->readingTime(); ?></small></p>
        </div>
            <p class="postDate mb-0 text-end"><a href="<?php echo $page->permalink(); ?>"><?php echo $page->date('j M Y'); ?></a></p>
    </li>
<?php endforeach ?>
</ul>
This list displays all my latest posts on the front page, from any category. I was hoping to exclude posts one specific category from this list.

Re: Help needed: Exclude Category in Posts Index (home)

Posted: Tue Jan 20, 2026 10:25 pm
by Edi
You can exclude a category with an if condition.

For example, if you want exclude the category "Exclude", you can use the following:

Code: Select all

<?php foreach ($content as $page) : ?>
	<?php if ($page->category() !== 'Excluded') : ?>
		...
	<?php endif; ?>
<?php endforeach; ?>

Re: Help needed: Exclude Category in Posts Index (home)

Posted: Wed Jan 21, 2026 2:44 am
by yukinaze
Thank you! This works for me.

Is it possible to display that excluded category as a separate list in a different section of the homepage where the above script is also without conflict? All good if not.

Re: Help needed: Exclude Category in Posts Index (home)

Posted: Thu Jan 22, 2026 9:44 pm
by Edi
You can use the inverse condition (=== instead of !==):

Code: Select all

<?php if ($page->category() === 'Excluded') : ?>

Re: Help needed: Exclude Category in Posts Index (home)

Posted: Fri Jan 23, 2026 11:53 am
by yukinaze
This works! Thank you