Community Forums › Forums › Archived Forums › General Discussion › How to add a class to an image within loop
- This topic has 3 replies, 2 voices, and was last updated 11 years, 1 month ago by cdils.
-
AuthorPosts
-
February 1, 2013 at 11:08 am #17096J KornMember
Hey all,
I'm new to Genesis and still trying to find my way around all of the hooks and filters Genesis makes available. I'm attempting to add a class to the image within a loop on a custom post archive page. To do so, I was attempting to use genesis_get_image_default_args, however, that doesn't seem to be working.
Here is the code I'm currently using:
function korndev_archive_image( $args ){ $args = array( 'format' => 'html', 'size' => 'full', 'num' => 0, 'attr' => array('class'=>'aligncenter'), 'fallback' => 'first-attached', ); return $args; } add_filter('genesis_get_image_default_args','korndev_archive_image');
Am I doing something wrong? Missing something? Any help would be greatly appreciated!
Thanks!
February 3, 2013 at 4:37 pm #17698cdilsParticipantAre you using your own custom loop/query or using genesis_custom_loop to loop through your posts?
You might take a look at image.php in the Genesis theme to see how it's handling images. Looks like
genesis_get_image_default_args
is called in the genesis_get_image function, which uses wp_get_attachment_image (See how style classes are passed to this last function in the codex: http://codex.wordpress.org/Function_Reference/wp_get_attachment_image)I'm trying to be helpful and not send you off following rabbits. 🙂 If that doesn't get you going in the right direction, maybe you can post the entire contents of your archive page so I can see your function in context.
Cheers,
Carrie
Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂
I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.
February 4, 2013 at 4:48 pm #18058J KornMemberThanks for the response, Carrie.
Are you using your own custom loop/query or using genesis_custom_loop to loop through your posts?
No. I'm using a template, archive-customtype.php, and within that, just trying to filter the image to add in/modify the class. I was looking through the Genesis code, specifically the image.php file and saw the following within genesis_get_image:
$defaults = apply_filters( 'genesis_get_image_default_args', array( 'format' => 'html', 'size' => 'full', 'num' => 0, 'attr' => '', 'fallback' => 'first-attached', ) );
So, I assumed I could filter the genesis_get_image_default_args, however, my code above seems to have no effect. I've found another way around what I was trying to do, but seems like using genesis_get_image_default_args would have made more sense.
For your reference, here is what my archive template looked like before (pretty straight forward):
remove_action( 'genesis_before_post_content', 'genesis_post_info' ); // Remove post info remove_action( 'genesis_after_post_content', 'genesis_post_meta' ); // Remove post meta add_filter( 'genesis_get_image_default_args', 'korndev_archive_image'); // Modify image function korndev_archive_image( $args ){ $args = array( 'attr' => array('class'=>'aligncenter') ); return $args; } genesis();
Thanks!
February 4, 2013 at 5:44 pm #18087cdilsParticipantCheck out this thread:
http://wordpress.org/support/topic/center-feature-images-only
Maybe you could use a CSS hack until the fix is included in 2.0? You could add a body class to your archive template to be able to specifically target just that page with your CSS (Here's a good article on body classes: http://designsbynickthegeek.com/tutorials/dynamic-body-classes).
Keep me posted. 🙂
Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂
I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.