Home › Forums › Support › How to wrap loop (generate_do_template_part) ? This topic has 7 replies, 2 voices, and was last updated 3 years, 5 months ago by Tom. Viewing 8 posts - 1 through 8 (of 8 total) Author Posts 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 #1509881 TomLead Developer Lead Developer Hi 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>'; October 29, 2020 at 3:04 pm #1510230 Fabien 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 #1511481 TomLead Developer Lead Developer You 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. October 31, 2020 at 3:32 am #1512037 Fabien Same issue, it wraps the whole post (item) and not the whole loop… October 31, 2020 at 11:24 am #1512702 TomLead Developer Lead Developer Aha, 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>'; } ); November 2, 2020 at 1:15 pm #1515216 Fabien Thanks Tom, but if I do that, it also wraps the page-header… November 2, 2020 at 2:34 pm #1515297 TomLead Developer Lead Developer For 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>'; } } ); Author Posts Viewing 8 posts - 1 through 8 (of 8 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In