I'm trying to display the author name as a tag. I looked at many forums and it's referring to the get_author
methods and the PHP files from the template PHP. However, I do not know what changes to make in the get_author
method in order to return his name as a tag for a simple blog post.
I've looked at the following references:
- https://codex.wordpress.org/Template_Tags#Author_tags
- https://codex.wordpress.org/Function_Reference/the_author
I do not know which files to edit and where to put it as PHP is not my go to language. It would be really helpful if someone can guide me and help me return the author's name as a tag.
It should display something like:
Posted by author name (but it's a tag)
When I do this:
This post was written by <!--?php the_author(); ?-->
It doesn't display the authors name.
Right before my post in dashboard:
<p>The author of the post: <?php the_author(); ?></p>
After doing more research, it says this code must be put in the themes's index.php
however, I do not know where in that index.php
.
Reference:
<!-- Display a comma separated list of the Post's Categories. -->
<p class="postmetadata">Posted in <?php the_category(', '); ?><?php the_author(); ?></p>
<?php get_header(); ?>
<div id="middle">
<div id="container">
<div id="ipilogue_logo"></div>
<!-- Display the Time. -->
<?php the_time('F j, Y'); ?><br/><br/>
<!-- Start the Loop. -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- The following tests if the current post is in category 3. -->
<!-- If it is, the div box is given the CSS class "post-cat-three". -->
<!-- Otherwise, the div box will be given the CSS class "post". -->
<?php if ( in_category('3') ) { ?>
<div class="post-cat-three">
<?php } else { ?>
<div class="post">
<?php } ?>
<!-- Display the Title as a link to the Post's permalink. -->
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<!-- Display the Time. -->
<small><?php the_time('F j, Y'); ?></small>
<!-- Display the Post's Content in a div box. -->
<div class="entry">
<?php the_content(); ?>
</div>
<p>The author of the post: <?php the_author(); ?></p>
<!-- Display a comma separated list of the Post's Categories. -->
<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
</div> <!-- closes the first div box -->
<!-- Stop The Loop (but note the "else:" - see next line). -->
<?php endwhile; else: ?>
<!-- The very first "if" tested to see if there were any Posts to -->
<!-- display. This "else" part tells what do if there weren't any. -->
<p>Sorry, no posts matched your criteria.</p>
<!-- REALLY stop The Loop. -->
<?php endif; ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</div>
</div>
<?php the_author(); ?>