[Support request] Display information according to the author ownership

Home Forums Support Display information according to the author ownership

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1094897
    Hilton

    Hi,

    Just below the breadcrumbs we display the author information (from that post). But we don’t want to display it for all authors. This way, how can we select this or that author to de displayed.

    I’ve tried to use the following, but it didn’t work

    <?php if ( is_author( '15' )  ) : ?>
        <div class="specialist"><img src="https://xxxxxx.com.br/wp-content/uploads/2019/11/xxxx.png" /> Specialist: <?php the_author_posts_link(); ?></div>
    <?php endif; ?>

    The element hook is configured to display before content to all posts.

    #1095021
    Hilton

    This one below didn’t work either

    <?php if( $post->post_author == '15' ) { ?>
        <div>Your code here</div>
    <?php } ?>
    #1095149
    David
    Staff
    Customer Support

    Hi there,

    try this:

    $author_id = get_post_field('post_author', get_the_ID());
    <?php if( $author_id == '15' ) { ?>
        <div>Your code here</div>
    <?php } ?>
    #1095228
    Hilton

    Hi David,

    It worked, thanks 😉

    But if I’d like to add one information for authors IDs 14 and 15, and another information for author ID 16, the code below is appropriate or I can use another one that would be better?

    <?php $author_id = get_post_field('post_author', get_the_ID()); ?>
    <?php if( $author_id == '15' || $author_id == '14' ) { ?>
        <img src="/image1.png">  <div class="specialist-mbf">Specialist: <?php the_author_posts_link(); ?></div>
    <?php } ?>
    <?php if( $author_id == '16' ) { ?>
        <img src="/image2.png">  <div class="specialist-mbf">Created by: <?php the_author_posts_link(); ?></div>
    <?php } ?>
    #1095628
    David
    Staff
    Customer Support

    If you only need it for a few authors then the code you have above is perfect.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.