Sweet Category Index With Post Counter

by | Nov 8, 2017 | Resource, Video |

Hey teq-ies ! We are back with another sweet video tutorial for you. You are going to build a category index ( basically an overview of post categories ) that also shows you dynamically how many posts you have in the given category. Cool, right ? Let’s get to it !

Feel free to also download the layout (link below) and use it wherever you like it. If you have any questions about the tutorial or about the video, please leave us a comment on our facebook page !

This is the script the goes along with the layout. It is responsible for adding a new custom shortcode. Insert it into your functions.php file (after <?php) . Make sure to backup the file or even your complete wordpress instance before you make any changes. Shoutout to Ahmed Mahdi, who came up with the script.

 

function category_post_count ($atts) {

    $atts = shortcode_atts( array(
        'category' => null
    ), $atts );

    $term = get_term_by( 'slug', $atts['category'], 'category');

    return ( isset( $term->count ) ) ? $term->count : 0;
}

add_shortcode( 'category_post_count', 'category_post_count' );

 

 

Get this layout for free

No sign-up required
Download