[Support request] New archive template

Home Forums Support [Support request] New archive template

Home Forums Support New archive template

  • This topic has 12 replies, 2 voices, and was last updated 3 months ago by Elvin.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1969987
    Hilton

    Hello, I would like to use the structure of a page in a category called “recipes”. So I created the file “category-recipes.php” and pasted the code from page.php. Then I replaced this part here (1) with this one (2). Now I have one pending issue, that is using the left sidebar (instead of the right default one).

    (1)

    /**
    * generate_before_main_content hook.
    *
    * @since 0.1
    */
    do_action( 'generate_before_main_content' );
    if ( generate_has_default_loop() ) {
    while ( have_posts() ) :
    the_post();
    generate_do_template_part( 'page' );
    endwhile;
    }
    /**
    * generate_after_main_content hook.
    *
    * @since 0.1
    */
    do_action( 'generate_after_main_content' );

    (2)

    <?php echo facetwp_display( 'facet', 'cozinha' ); ?>
    <?php echo facetwp_display( 'facet', 'ingredients' ); ?>
    <?php echo facetwp_display( 'facet', 'dieta' ); ?>
    <?php echo facetwp_display( 'facet', 'refeio' ); ?>
    <?php echo facetwp_display( 'template', 'recipes' ); ?>
    #1970249
    Elvin
    Staff
    Customer Support

    Hi there,

    It’s not ideal to replace default templates especially the parts with do_action(...) because the theme uses hooks to add in its parts.

    Can you specify where you want these facetwp_display() to display? Perhaps you don’t need a child theme for this and maybe add them in through hooks. Here’s a hook visual guide – https://docs.generatepress.com/article/hooks-visual-guide/

    It’s not 100% complete but most of the hooks are there.

    A wise man once said:
    "Have you cleared your cache?"

    #1970266
    Hilton

    Hi Elvin,

    This facetwp_display( ) is used by a plugin called facetWP to add filters and template to a page like this https://prnt.sc/1wwz776 . For that I believe I could use hooks, but do you know how to do it in practice? Do I have to create a template like โ€œcategory-recipes.phpโ€? How can I have an archive with no content (only header and footer) so I can put filters and template from facetWP?

    Thanks

    #1970274
    Elvin
    Staff
    Customer Support

    How can I have an archive with no content (only header and footer) so I can put filters and template from facetWP?

    the category archive pages, by default, only has the name of the category, the term description and the loop.

    But you can easily remove all of that with this filter:

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

    You then place these codes on a Hook Element with a display rule location of “Post Category Archive” and set the hook to generate_before_main_content.

    <?php echo facetwp_display( 'facet', 'cozinha' ); ?>
    <?php echo facetwp_display( 'facet', 'ingredients' ); ?>
    <?php echo facetwp_display( 'facet', 'dieta' ); ?>
    <?php echo facetwp_display( 'facet', 'refeio' ); ?>
    <?php echo facetwp_display( 'template', 'recipes' ); ?>

    Note: Make sure you set check “Execute PHP” on the hook element.

    This effectively removes the default loop of the category archive page and replaces it with whatever facetwp_display() outputs. ๐Ÿ˜€

    Alternatively, if facetwp_display() has a shortcode or gutenberg block equivalent, you can do replace Hook Element with a Block element – Hook for a better styling and layout experience. ๐Ÿ˜€

    A wise man once said:
    "Have you cleared your cache?"

    #1970275
    Hilton

    To make it clearer what I want is to put the content from inside this page https://bit.ly/3ngqUEj in this category page https://bit.ly/3G0MBkB

    #1970277
    Hilton

    So in practice, as I only need to change the “recipe” category, in the function I would need to specify the category so that it doesn’t apply to all, right?

    So, considering that the category url ends with /recipe/, the function would be this, right?

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

    Or if the category ID is 59, the function would be this:

    add_filter( 'generate_has_default_loop', function( $show ) {
    
        if ( is_category( '59' ) ) {
            return false;
        }
    
        return $show;
    } );
    #1970281
    Elvin
    Staff
    Customer Support

    So in practice, as I only need to change the โ€œrecipeโ€ category, in the function I would need to specify the category so that it doesnโ€™t apply to all, right?

    That’s correct. ๐Ÿ™‚

    So, considering that the category url ends with /recipe/, the function would be this, right?

    Yes that’s correct as well.

    Or if the category ID is 59, the function would be this:

    You’ll have to remove the ' before and after 59 if its an ID because IDs are integer values.

    Like this:

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

    And say for example, you want to specify multiple ids, you can do it like this:

    add_filter( 'generate_has_default_loop', function( $show ) {
    
        if ( is_category( array(59,60,61,62) ) ) {
            return false;
        }
    
        return $show;
    } );

    Reference – https://developer.wordpress.org/reference/functions/is_category/

    A wise man once said:
    "Have you cleared your cache?"

    #1970291
    Hilton

    Thanks a lot Elvin! ๐Ÿ™‚

    #1970316
    Elvin
    Staff
    Customer Support

    No problem. Let us know if you need further help with this. ๐Ÿ˜€

    A wise man once said:
    "Have you cleared your cache?"

    #1970968
    Hilton

    Hi,

    One more question, if I have this CSS below:

    .sidebar .widget .widget-title {
    	border-top: 5px solid #f7f7f7;
        border-bottom: 1px solid #f7f7f7;
    	padding: 5px 0;
    	font-size: 20px;
    }

    And this class .flyout-row h3 has the same CSS, I can use this:

    .sidebar .widget .widget-title, .flyout-row h3 {
    	border-top: 5px solid #f7f7f7;
        border-bottom: 1px solid #f7f7f7;
    	padding: 5px 0;
    	font-size: 20px;
    }

    Or I have to add a separate CSS to .flyout-row h3 ?

    Thanks

    #1971306
    Elvin
    Staff
    Customer Support

    Assuming you want .flyout-row h3 to have the exact same styling as the widget titles then that should be fine. ๐Ÿ™‚

    A wise man once said:
    "Have you cleared your cache?"

    #1971422
    Hilton

    Perfect ๐Ÿ™‚
    Thanks

    #1971427
    Elvin
    Staff
    Customer Support

    No problem. ๐Ÿ˜€

    A wise man once said:
    "Have you cleared your cache?"

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