Site logo

Archived topic

Display information according to the author ownership

4 replies · Started by Hilton on December 5, 2019

Viewing posts 1–5 of 5

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.

This one below didn't work either

<?php if( $post->post_author == '15' ) { ?>
    <div>Your code here</div>
<?php } ?>

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

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

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

This archived topic is closed to new replies.