[Resolved] How do I disable the loop on an archive?

Home Forums Support [Resolved] How do I disable the loop on an archive?

Home Forums Support How do I disable the loop on an archive?

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1193463
    Nates

    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()
    {
    
    ...
    
    }
    
    
    #1194067
    Tom
    Lead Developer
    Lead Developer

    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.

    #1898426
    David Perez Garcia

    Did you make that filter?

    #1898434
    David Perez Garcia
    #1899521
    Tom
    Lead Developer
    Lead Developer

    Yes – you can now disable the default loop using that filter 🙂

    #2553690
    Nates

    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' );
    }
    #2553939
    David
    Staff
    Customer Support

    Hi there,

    try this PHP Snippet:

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

    Thanks I found a way.

    #2556242
    David
    Staff
    Customer Support

    Glad to hear that

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.