- This topic has 7 replies, 2 voices, and was last updated 1 year, 7 months ago by
Tom.
-
AuthorPosts
-
October 28, 2020 at 1:19 pm #1508484
Fabien
Hi,
I am using the following function to change the loop on my category pages :
/** * Change loop on archive. */ add_filter( 'generate_do_template_part', function( $do ) { if ( is_category() ) { return false; } return $do; } ); add_action( 'generate_before_do_template_part', function() { if ( is_category() ) { get_template_part('partials/content', 'archive'); } } );
How can I wrap my loop with some
<div></div>
?Thanks !
October 29, 2020 at 9:54 am #1509881Tom
Lead DeveloperLead DeveloperHi there,
Your markup would ideally go into the
partials/content-archive.php
file.However, you could also do this:
echo '<div>'; get_template_part('partials/content', 'archive'); echo '</div>';
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentOctober 29, 2020 at 3:04 pm #1510230Fabien
Thanks Tom, but if I do that, all posts are individually wrapped… I just want to wrap around my loop like :
<div class="wrapper"> <article>...</article> <article>...</article> <article>...</article> </div>
October 30, 2020 at 10:59 am #1511481Tom
Lead DeveloperLead DeveloperYou could try this:
add_action( 'generate_before_do_template_part', function() { echo '<div class="wrapper">'; } ); add_action( 'generate_after_do_template_part', function() { echo '</div>'; } );
You’d just need to add your conditions to each function.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentOctober 31, 2020 at 3:32 am #1512037Fabien
Same issue, it wraps the whole post (item) and not the whole loop…
October 31, 2020 at 11:24 am #1512702Tom
Lead DeveloperLead DeveloperAha, ok, you’ll need to do this:
add_action( 'generate_before_main_content', function() { echo '<div class="wrapper">'; } ); add_action( 'generate_after_main_content', function() { echo '</div>'; } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 2, 2020 at 1:15 pm #1515216Fabien
Thanks Tom, but if I do that, it also wraps the page-header…
November 2, 2020 at 2:34 pm #1515297Tom
Lead DeveloperLead DeveloperFor archives, you may need to do this:
add_action( 'generate_archive_title', function() { if ( is_archive() ) { echo '<div class="wrapper">'; } }, 20 ); add_action( 'generate_after_loop', function() { if ( is_archive() ) { echo '</div>'; } } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.