- This topic has 12 replies, 2 voices, and was last updated 2 years, 6 months ago by Elvin.
-
AuthorPosts
-
October 20, 2021 at 11:59 am #1969987Hilton
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' ); ?>
October 20, 2021 at 7:49 pm #1970249ElvinStaffCustomer SupportHi 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.
October 20, 2021 at 8:55 pm #1970266HiltonHi 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
October 20, 2021 at 9:32 pm #1970274ElvinStaffCustomer SupportHow 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. ๐
October 20, 2021 at 9:37 pm #1970275HiltonTo 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
October 20, 2021 at 9:45 pm #1970277HiltonSo 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; } );
October 20, 2021 at 9:53 pm #1970281ElvinStaffCustomer SupportSo 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/
October 20, 2021 at 10:16 pm #1970291HiltonThanks a lot Elvin! ๐
October 20, 2021 at 11:31 pm #1970316ElvinStaffCustomer SupportNo problem. Let us know if you need further help with this. ๐
October 21, 2021 at 9:29 am #1970968HiltonHi,
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
October 21, 2021 at 4:41 pm #1971306ElvinStaffCustomer SupportAssuming you want
.flyout-row h3
to have the exact same styling as the widget titles then that should be fine. ๐October 21, 2021 at 8:27 pm #1971422HiltonPerfect ๐
ThanksOctober 21, 2021 at 9:00 pm #1971427ElvinStaffCustomer SupportNo problem. ๐
-
AuthorPosts
- You must be logged in to reply to this topic.