Add Avatar to MOCHA Home Featured Post Only

Community Forums Forums Design Tips and Tricks Add Avatar to MOCHA Home Featured Post Only

This topic is: resolved

This topic contains 8 replies, has 2 voices, and was last updated by  braddalton 1 year, 3 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #43603

    Kelli
    Participant
    Post count: 8

    I’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.com
    #43621

    braddalton
    Participant
    Post count: 9752

    Hi Kelli

    Will that specific post change when you publish more posts? Or do you want it to stay on one specific post?

    Try this:
    [php]
    if (is_sticky( ’007′ ) ) {
    [/php]
    Or
    [php]
    if (is_sticky( ’007′ ) && is_home() ) {
    [/php]
    Or
    [php]
    if (is_single(’007′) || is_home() ) {
    [/php]
    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.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #43792

    Kelli
    Participant
    Post count: 8

    Hi 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?

    #43800

    braddalton
    Participant
    Post count: 9752

    You’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.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #43814

    braddalton
    Participant
    Post count: 9752

    Could 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.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #43819

    Kelli
    Participant
    Post count: 8
    This reply has been marked as private.
    #43822

    braddalton
    Participant
    Post count: 9752

    Here’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.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #43831

    Kelli
    Participant
    Post count: 8

    That works perfectly! Thank you, Brad.

    Glad I found the idea on your site and happy to know you’re helping here at StudioPress, too!

    #43856

    braddalton
    Participant
    Post count: 9752

    No worries Kelli.

    Didn’t get your private message. Not sure why.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.