Site logo

Archived topic

How do I disable the loop on an archive?

8 replies · Started by Nates on March 12, 2020

Viewing posts 1–9 of 9

Hi

On a category or tag page, I don't want to display the normal posts. I want to disable it, is it possible via hook/filter without having to create a category.php and tags.php in a child theme.

When a category page loads, I want to display my own thing, compltely custom code. I am currently using genesis framework and would like to move to Generate Press.

I do the following in genesis. Firstly, disable the loop (genesis_loop), then create an action to add my own function instead - audio_player().

Can this be achieved in GP?

add_action('genesis_before_content_sidebar_wrap', 'qc_category_player');
function qc_category_player()
{
    if (is_category()) {
        remove_action('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
        add_action('genesis_loop', 'audio_player'); // Add custom output
    }
}

function audio_player()
{

...

}

Hi there,

This isn't possible at the moment, unfortunately.

However, I've made a note to add a filter in GP 2.5.0 so we can disable the standard loop. This will be important moving forward with some of our own plans, as well.

For now, a custom page template is the best method.

You could create a new template, then do this:

add_filter( 'template_include', function( $template ) {
    if ( is_category() ) {
        return locate_template( 'your-blank-template.php' );
    }

    return $template;
} );

That way you don't need to overwrite the standard theme template.

Did you make that filter?

Yes - you can now disable the default loop using that filter :)

Please can provide a clear way to disable the loop in an archive on a all categories?

Where exactly is this code used? I tried the following in the functions.php

if (is_category())
{
	add_filter( 'generate_has_default_loop', '__return_false' );
}

Hi there,

try this PHP Snippet:

add_filter( 'generate_has_default_loop', function($show){
    if ( is_category() ) {
        return false;
    }
    return $show;
} );

Thanks I found a way.

Glad to hear that

This archived topic is closed to new replies.