my code

Tobias Hopp

Category Limit / Template Part based on post count
by Tobias Hopp

This snippet includes a temlate part, wheter the number of posts in a category hits a limit or not

Snippet options

Download: Download snippet as category-limit-template-part-based-on-post-count.php.
Copy snippet: For this you need a free my code account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<?php $category_limit = 5; // Enter your threshhold/limit number here
	$category = get_the_category();
	$number_of_posts = $category[0]->category_count;

	if($number_of_posts >= $category_limit) {
		echo 'Limit hit, include template part';
	} else {
		echo 'Limit not hit, not including template part';

Create a free my code account now.

my code is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.