Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add Avatar to MOCHA Home Featured Post Only
Tagged: avatar, featured post, home, Mocha
- This topic has 8 replies, 2 voices, and was last updated 13 years ago by
Brad Dalton.
-
AuthorPosts
-
June 2, 2013 at 8:57 am #43603
Kelli
MemberI've used @braddalton 's wonderful code to add my avatar before the post title on single posts. I'm using Mocha and I'd like the avatar to show on the home page posts also but only on the 1st featured post---not on the following 6 excerpts on the home page.
There must be a specific conditional to code it this way, but I can't figure it out. Can you Brad or anyone else figure out what that conditional would be?
I've tried if (is_single() || is_home() ) { but it puts the avatar on the featured post and the 6 excerpts, but I would like the avatar on the 1st post (featured post) on the home page only.
Help?
Site: http://sweetnessoflife.com
Thank you!
-Kelli
http://sweetnessoflife.comJune 2, 2013 at 11:22 am #43621Brad Dalton
ParticipantHi Kelli
Will that specific post change when you publish more posts? Or do you want it to stay on one specific post?
Try this:
if (is_sticky( '007' ) ) {Or
if (is_sticky( '007' ) && is_home() ) {Or
if (is_single('007') || is_home() ) {Returns true if "Stick this post to the front page" check box has been checked for the current post.
Change the 007 to the i.d of the post which you can grab from the source code or by hovering over the edit or delete button for that post.
June 3, 2013 at 6:14 am #43792Kelli
MemberHi Brad, the post changes... it is always the most recent post published. Do you think there's a way in Mocha to identify it for this purpose?
June 3, 2013 at 6:35 am #43800Brad Dalton
ParticipantYou'll need a query for that. I don't think there's a conditional tag for the most recent post.
Once you have the query, you can then put it into a custom function with the code you have already.
I'll see if I can get you the query.
June 3, 2013 at 8:01 am #43814Brad Dalton
ParticipantCould you please paste the code you used for your home page here thanks.
I'd like to test it with the query and make sure it works before posting the entire snippet.
June 3, 2013 at 8:20 am #43819Kelli
MemberThis reply has been marked as private.June 3, 2013 at 8:28 am #43822Brad Dalton
ParticipantHere's the solution I tested which works:
Code not displaying? Grab it from Github.
Credit to s_ha_dum WordPress.stackexchange.com for the query.
June 3, 2013 at 8:54 am #43831Kelli
MemberThat works perfectly! Thank you, Brad.
Glad I found the idea on your site and happy to know you're helping here at StudioPress, too!
June 3, 2013 at 11:34 am #43856Brad Dalton
Participant -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.