WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Featured Posts filter problem on front page (5 posts)

  1. Charles Kelley
    Member
    Posted 3 years ago #

    I need to create a 'featured posts' section on the front page of a site I'm working on.

    Simply, if a post is written by one author specifically, I need it to display that person's name and avatar along with the permalink and the post date. However, if it's written by another author (a psedu-admin account they'll use for posting general info not attributed to any one author), I need it NOT to display a the name and avatar and simply render the permalink and the post date.

    As I'm no PHP guru and is_author only render's in the archives page, is there a way to do this in the loop? Code is below ('xx' represents authors nicename):

    <?php  if (is_author( 'xx' )) { ?>
    
    <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br></h3>
    <small><?php echo get_the_date('F j, Y'); ?></small><br><br>
    
    <?php  } else { ?>
    
    <div style="float:right; padding:0px 10px;"><?php echo get_avatar( get_the_author_email(), '40' ); ?></div>
    
    <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br></h3>
    <small>by <?php the_author(); ?> | <?php echo get_the_date('F j, Y'); ?></small><br><br>
    
    <?php } ?>
    
    <?php endwhile; ?>

    Also, am I doing something wrong here, other than the is_author reference?? The code works perfectly now but render the html for the 'else' statement.

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    you could try one of these:

    to get the post's authors name:
    http://codex.wordpress.org/Function_Reference/get_the_author

    or to get the post's authors id:
    $post->post_author

  3. Charles Kelley
    Member
    Posted 3 years ago #

    Alchymyth-

    Thanks for the suggestion. I looked at that, but all that would do is return their 'publicly display as' name. That's not my problem as the author's name will display just fine.

    As described above, I need the code to check and see which author it is. If it's one specific author, I need it to return one type of format (without an avatar and the author's name) within the loop and if it's anyone else, return a completely separate format (which includes the formerly excluded attributes).

  4. Charles Kelley
    Member
    Posted 3 years ago #

    Essentially, I need an is_author sort of code that will actually work on something other than an archive page, or make is_author work on the archive page. Haven't been able to find anything on here or on google.

  5. Charles Kelley
    Member
    Posted 3 years ago #

    Nevermind, ended up doing a workaround of sorts. As is_author only works in the archive page, it's a no go.

    I used the code as above and changed it to the 'in_category()' conditional statement and assigned the posts I wanted to have no info to a specific extra category, which I wanted to avoid. But hey, it works. Hope this helps.

Topic Closed

This topic has been closed to new replies.

About this Topic