• Alright im having trouble figuring this one out. If I do the following code it doesnt work, is there something specific in your template causing to not to work properly?

    <?php
    function exclude_category($query) {
    if ( $query->is_home() )
    {
    $query->set('cat', '-1');
    } 
    
    return $query;
    } 
    
    add_filter('pre_get_posts', 'exclude_category');
    ?>

    Anyways the above code should remove category one from the home but it doesnt work.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter foodada

    (@foodada)

    NM I went a different route using this in the template file

    $main_categories = get_categories( array(
    	'taxonomy' => 'category',
    	'parent' => 0,
    	'hide_empty' => 0,
    	'exclude' =>'1',
    ) );

    Excellent. Worked like a charm for me.
    After adding a child theme, I added the one bottom line to that which already existed in the template-knowledgebase.php fie.

    Hi all,

    Does anyone know how to achieve this with the number of articles under each category on the main page?
    For example I would only like to show x amount of articles under each category?
    At the moment the default seems to be to show 10

    Thanks in advance.

    Thread Starter foodada

    (@foodada)

    settings> reading > Blog pages show at most

    Change the default 10 to whatever you want.

    Thread Starter foodada

    (@foodada)

    Josh, you can also make page template doing the same thing. I found this to make my site more user friendly. I could then group my categories according to that page.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Filtering categories off the main page’ is closed to new replies.