[Support request] Custom Post Type Archive in Columns

Home Forums Support [Support request] Custom Post Type Archive in Columns

Home Forums Support Custom Post Type Archive in Columns

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #1642547
    Johan

    Hello and thank you for your great product!
    However, I have a problem:
    I created a child theme a “Custom Post Type” and when I display it by archive the layout is in one column (see here: https://dev1.directsolutions.fr/offres/nos-formations / or https://dev1.directsolutions.fr/offres/nos-formations/securite-incendie/).
    I would like it to display in 2 or three columns. I have tried several of the solutions given in these pages without it working.
    This does not work:

    add_filter (‘generate_blog_columns’, ‘tu_formation_columns’);
    function tu_formation_columns ($ columns) {
    if (is_post_type_archive (‘training’)) {
    return true;
    }
    return $ columns;
    }

    Could you give me a solution?
    Thank you
    Johan Puisais

    #1643222
    David
    Staff
    Customer Support

    Hi there

    can you confirm the Post Type you have set for the is_post_type_archive is correct – it should be formation

    #1643240
    Johan

    Hello and thank you David
    Yes, I confirm it to you.
    What is displayed here are the “custom post type” “formation” classified into categories

    #1643972
    David
    Staff
    Customer Support

    In the code you provided above – you have:

    if (is_post_type_archive ('training')) {

    This needs to be:

    if (is_post_type_archive ('formation')) {

    #1644001
    Johan

    Yes I put “training” … in fact I am French and during the translation I forgot to modify “formation” πŸ˜‰ But yes my code is :

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

    In fact I have looked at all the forum answers that may apply to my problem here and have tested most of them. Without results…
    Is it due to the version of my GeneratePress (I have the latest one)? Because the examples given do not seem to be the same as the original code I find in my files.

    #1644345
    David
    Staff
    Customer Support

    That code should work – how are you adding the code to your site?

    #1645179
    Johan

    Hello David,
    Yes I added this code in the functions.php file of my child theme in “themes/generatepress_child”

    #1645983
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    What if you use nos-formations instead?

    Let us know πŸ™‚

    #1646620
    Johan

    Hello Tom,
    I did it and I just do it again now. It doesn’t change anything

    For additional information and if this can help you, I also created an “archive-formation.php” which is not taken into account by the system while my “single-formation.php” works. It may not be related but …

    #1648396
    Tom
    Lead Developer
    Lead Developer

    I suppose the first thing we need to do is figure out if our condition is right.

    Does this output anything on your page?:

    add_action( 'generate_before_header', function() {
        if ( is_post_type_archive( 'formation' ) ) {
            echo 'Hello world';
        }
    } );

    If not, it means the condition is wrong and needs to be tweaked.

    #1650041
    Johan

    Hello Tom,

    I just inserted this code and nothing is displayed, no “Hello Word” πŸ™
    The condition of must therefore not be the right one.

    #1650100
    David
    Staff
    Customer Support

    Instead of:

    if ( is_post_type_archive( 'formation' ) ) {

    try this in Tom’s function:

    if ( is_category( 'formation' ) ) {

    #1650101
    Johan

    After some tests I see that
    add_action (‘generate_before_header’, function () {
    if (is_category ()) {
    echo ‘Hello everyone’;
    }
    });
    works, as well as “is-archive ()”

    #1650105
    Johan

    “if ( is_category( ‘formation’ ) )” not works but “if ( is_category( ) )” Yes

    And “if ( is_category( ‘nos-formations’ ) )” works only at “https://dev1.directsolutions.fr/offres/nos-formations/”

    #1650222
    David
    Staff
    Customer Support

    So this should work:

    add_filter( 'generate_blog_columns','tu_formation_columns' );
    function tu_formation_columns( $columns ) {
        if ( is_category( 'nos-formations' ) ) {
            return true;
        }
        return $columns;
    }

    Whatever archives does it need to be applied to?

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