[Resolved] Use columns for CPT on author archive

Home Forums Support [Resolved] Use columns for CPT on author archive

Home Forums Support Use columns for CPT on author archive

  • This topic has 9 replies, 3 voices, and was last updated 4 years ago by Tom.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #821323
    Aart

    Hi,

    I have a custom post type called ‘recept’. I’m trying to do two things:

    1. Show all ‘recept’ content on their authors’ respective archive pages.
    2. Adding GP columns and masonry to all archive pages of this post type.

    I’ve managed 1) by creating a little plugin, but I’m having some trouble with 2). I have both columns and masonry working with the help of these code snippets, but I can’t get it to work on the author pages.

    I hope you can point me in the right direction.

    Best regards,

    Aart

    GeneratePress 2.2.2
    #821440
    Leo
    Staff
    Customer Support

    Hi there,

    What’s the condition you are currently using?

    Have you tried this?
    https://codex.wordpress.org/Conditional_Tags#An_Author_Page

    Everything should be listed on that page.

    Let me know πŸ™‚

    #822487
    Aart

    Hi Leo,

    I’m currently using this for the post archive pages:

    add_filter( 'generate_blog_columns','tu_portfolio_columns' );
    function tu_portfolio_columns( $columns ) {
        if ( is_post_type_archive( 'recept' ) ) {
            return true;
        }
    
        return $columns;
    }

    I want to extend this to all archives, including the author archive, but I’m not sure how to do that.

    #822728
    Leo
    Staff
    Customer Support
    #826303
    Aart

    Hi Leo, thanks your help. I tried changing condition to is_author, like this:

    add_filter( 'generate_blog_columns','tu_portfolio_columns' );
    function tu_portfolio_columns( $columns ) {
        if ( is_author ) {
            return true;
        }
    	
        return $columns;
    }

    Sure enough it worked on the author archive pages, showing the content in columns. Unfortunately it also affected the rest of the site, causing page sections to overlap each other on single pages (like the comment box overlapping the content) and the homepage (which contains WP Show Posts).

    So I guess this is not the full solution. I also don’t know how to apply this filter to both the post type archive and the author archives using the same code snippet. I’m sorry I don’t understand enough about PHP to do this myself, but I hope you can help me with the correct code.

    #826676
    Tom
    Lead Developer
    Lead Developer

    Hmm, it shouldn’t ever happen on single posts. Is there a specific page where I can see that happening?

    #826703
    Aart

    Hi Tom, thank you for replying. I’ve turned on the snippet again, so now can see it in action on any page, like this one (link). You can also see something strange happening on the front page: the footer is where the main content should start.

    This is the full snippet I’m using:

    add_filter( 'generate_blog_columns','tu_portfolio_columns' );
    function tu_portfolio_columns( $columns ) {
        if ( is_author ) {
            return true;
        }
    	
        return $columns;
    }
    
    add_filter( 'generate_blog_masonry','tu_portfolio_masonry' );
    function tu_portfolio_masonry( $masonry ) {
        if ( is_author ) {
            return 'true';
        }
    
        return $masonry;
    }

    I also tried disabling all GP Elements that are active, without result.

    #827018
    Tom
    Lead Developer
    Lead Developer

    Instead of is_author, try is_author().

    Let me know πŸ™‚

    #827059
    Aart

    Thank you so much Tom, that did it! πŸ™‚

    So now I’m using this as the filter for columns in all relevant views (author, taxonomy, archive):

    add_filter( 'generate_blog_columns','tu_portfolio_columns' );
    function tu_portfolio_columns( $columns ) {
        if ( is_author() ) {
            return true;
        }
        if ( is_tax( array( 'keuken', 'gerechtsoort' ) ) ) {
            return true;
        }
        if ( is_post_type_archive( 'recept' ) ) {
            return true;
        }
    	
        return $columns;
    }

    It’s working great, thanks again!

    #827523
    Tom
    Lead Developer
    Lead Developer
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.