Community Forums › Forums › Archived Forums › General Discussion › Add div class to custom category template
- This topic has 5 replies, 2 voices, and was last updated 7 years, 2 months ago by babrees.
-
AuthorPosts
-
January 29, 2017 at 1:37 am #200210babreesParticipant
I have a custom template for just one category.
Can I add a div to wrap each entry?January 29, 2017 at 7:02 am #200214Victor FontModeratorYou can probably hook into genesis_before_entry and genesis_after_entry with something like this:
add_action('genesis_before_entry','add_custom_div_open'); add_action('genesis_after_entry','add_custom_div_close'); function add_custom_div_open() { if ( is_category() ) { echo '<div class="my-custom-class">'; } } function add_custom_div_close() { if ( is_category() ) { echo '</div>'; }
}
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?January 29, 2017 at 7:54 am #200217babreesParticipantThanks Victor, but that that didn't work. Didn't make any difference at all.
I neglected to say I'm using Altitude theme, don't expect that would make a difference though.
January 29, 2017 at 12:03 pm #200224Victor FontModeratorI tested the code with Altitude Pro in my local environment and it works fine. How are you creating the category page? The is_category conditional works with category pages created from the menu. If you are creating a category page in some other fashion, you may have to use a different conditional. There's no way to tell without a link to your site.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?January 29, 2017 at 3:36 pm #200231babreesParticipantYes, I created the category from the menu, but I do have a category template...
<?php //* Remove the post title function remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); //* Add the post title function add_action( 'genesis_entry_content', 'genesis_do_post_title', 11 ); //* Remove the post info function remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); //* Remove the post content remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); //* Remove the post meta function remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); genesis();
This is the exact code I put into functions.php...
//* add new class div to wrap entry in photo gallery add_action('genesis_before_entry','add_custom_div_open'); add_action('genesis_after_entry','add_custom_div_close'); function add_custom_div_open() { if ( is_category( 'photo-gallery' ) ) { echo '<div class="photo-gallery-class">'; } } function add_custom_div_close() { if ( is_category( 'photo-gallery' ) ) { echo '</div>'; } }
January 30, 2017 at 4:31 am #200240babreesParticipantHi Victor - got it working!!!! My fault entirely. I had tried so many different things and I had inadvertently not deleted one bit I had tried previously and that was the problem!
I'd like to say thank you for all your help in this forum. Words can not say how much it is appreciated!
Thanks
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.