Tuesday, June 18, 2019

How to display author name and post

//to display author name
<?php
                     
                                global $post;
                                $author_id=$post->post_author;
                                ?>
                           
                       <strong><?php the_author_meta( 'display_name', $author_id );?> </strong>

<?php
                  global $post;
                          $author_id=$post->post_author;
                      ?>

//to display author post
             <?php
             $args = array(
                    'author'        =>  $author_id,
                    'orderby'       =>  'post_date',
                    'order'         =>  'ASC',
                    'posts_per_page' => -1
                    );
                   
                      $query = new WP_Query($args);
                      if($query->have_posts()):
                      while ($query->have_posts()):
                      $query->the_post();
                    ?>
           <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></li>
           <?php endwhile; endif; wp_reset_query(); ?>

//to display author media link
<?php
$twitter = get_the_author_meta( 'twitter', $post->post_author );
$facebook = get_the_author_meta( 'facebook', $post->post_author );
echo '<a href="https://twitter.com/' . $twitter .'" rel="nofollow" target="_blank">Twitter</a> |
<a href="'. $facebook .'" rel="nofollow" target="_blank">Facebook</a>';
?>

No comments:

Featured Post

Make money online

https://www.wpbeginner.com/beginners-guide/make-money-online/?fbclid=IwAR0_9_5aHmbB4rDisaPevdnO4uAgo0N9heHgPu1TjerjurE5ilD2NyzeB2A

Popular Posts