WordPress.org

Ready to get started?Download WordPress

Forums

the_author() not displaying anything, ideas? (14 posts)

  1. cownaetion
    Member
    Posted 6 years ago #

    Hi, just recently installed version 2.5 and for some reason the template tag 'the_author' is not working with the default theme nor my custom theme. I checked the include file (author-template.php) and it's fine and since I'm running this first on a personal workstation before making it live I checked the tables in MySQL and the data is there for the author. So I cannot understand why it's not displaying the data even on the default theme from a clean install. Any ideas? Thanks for your time.

  2. TrishaM
    Member
    Posted 6 years ago #

    Can you please post your code - how you're calling that function? Also it would be helpful to see what you're doing in your template for that page - author-template.php.

  3. moshu
    Member
    Posted 6 years ago #

    In the default it is commented out:
    <!-- by <?php the_author() ?> -->

  4. RosieMBanks
    Member
    Posted 6 years ago #

    Did you have a previous version (like 2.3) and the author function worked, but since you upgraded to 2.5 it doesn't work anymore? Or is this a new install?

    Also, it never hurts to check if you've read the docs.

    Woops... Moshu goes right to the heart of the matter.

  5. cownaetion
    Member
    Posted 6 years ago #

    Moshu: Your right it is commented out. Uncommented it works but doesn't work in the custom theme.

    Trish: I'm calling it the same exact way as in the default theme's index.php, 'the_author()' and...

    Rosie: I have checked the docs and copy/pasted almost all their code examples to no avail. However I am avoiding the loop by directly using a get_posts() method and using a 'foreach' loop, as such:


    <?php
    $myposts = get_posts('numberposts=1&offset=2&category=3');
    foreach ($myposts as $post) :
    ?>
    <h1><?php the_author() ?></h1>
    <?php endforeach; ?>

    Please note that other common tags are working, such as 'the_ID', 'the_excerpt', 'the_title', and 'the_permalink'. So why 'the_author' is not working I have no idea. Any help would be great, thanks for your time.

  6. RosieMBanks
    Member
    Posted 6 years ago #

    It's beyond my scope to figure it out... unless.... aren't you supposed to have a semicolon after that tag? Like this?

    <?php the_author(); ?>

    ...instead of what you have, which is this:

    <?php the_author() ?>

    Boy, wouldn't it be great if that's all that caused the problem?

  7. TrishaM
    Member
    Posted 6 years ago #

    From the Codex page

    "The author of a post can be displayed by using this Template Tag. This tag must be used within The Loop."

    I have not tried to use it the way you are, but I would suggest testing it from within the Loop, and if it works, you'll know it's not the function.

  8. cownaetion
    Member
    Posted 6 years ago #

    Rosie: I've tried with/without the semicolon, no go, However I did find the solution. When not using the loop, you need to manually prepare the data with setup_postdata($post), as such:

    '
    $query = get_posts('showposts=5');
    foreach($query as $post) {
    setup_postdata($post); //loads all data, including meta for access

    //resume adding template tags as normal
    }
    '
    So that would be the solution for all who are interested or for any one looking for info to absorb. Thanks all for the replies, appreciate it.

  9. moshu
    Member
    Posted 6 years ago #

    More Codex... :)
    If you tried to use the example from Template_Tags/get_posts - the_author doesn't seem to work with that first example code.
    However, it works with most of the others (that I have tried 5 minutes ago on a 2.5)

    EDIT. You found the solution while I was testing the code.

  10. cownaetion
    Member
    Posted 6 years ago #

    Well thanks for trying moshu, do appreciate the help. I'm sure I'll have more questions eventually when I start trying to develop some simple plugins and what not so don't go anywhere :)

  11. howarthj
    Member
    Posted 6 years ago #

    I'm very new to all this folks, so please hang on in there with me...

    I assume we put the solution to the the_author() not displaying issue in the index.php file.

    I've pasted my index.php below. Can anyone please tell me where to put the solution code you have described in your posts above?

    <?php get_header(); ?>
    
    	<div id="content">
    
    	<?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    				<h2 class="posttitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    				<div class="postmetadata"><?php the_time('jS F Y, h:i a ') ?> <!-- <?php _e('by') ?> <?php the_author() ?> --></div>
    				<div class="postentry">
    					<?php the_content(__('Continue reading'). " ‘" . the_title('', '', false) . "’ &raquo;"); ?>
    				</div>
    
    				<div class="postmetadata">
    					<?php if( function_exists('the_tags') )
    						the_tags(__('Tags: '), ', ', '');
    					?>
    					<span class="categ"><?php _e('Category:') ?></span> <?php the_category(', ') ?>&nbsp;&nbsp;|&nbsp;
    					<img src="<?php bloginfo('stylesheet_directory'); ?>/images/comments.gif" alt=" "/>
    					<?php comments_popup_link(__('Comment'), __('1 Comment'), __('% Comments')); ?>
    					<?php edit_post_link(__('Edit'), '&nbsp;|&nbsp;&nbsp;', ''); ?>
    					<img src="<?php bloginfo('stylesheet_directory'); ?>/images/hr.gif" alt=" "/>
    				 </div>
    			</div>
    
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link(__('&laquo; Previous Entries')) ?></div>
    			<div class="alignright"><?php previous_posts_link(__('Next Entries &raquo;')) ?></div>
    		</div>
    
    	<?php else : ?>
    		<div class="post">
    			<h2 class="posttitle"><?php _e('Not Found') ?></h2>
    			<div class="postentry"><?php _e('Sorry, no posts matched your criteria.'); ?>
    </div>
    		</div>
    
    	<?php endif; ?>
    
    	</div>
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    Many thanks.

  12. howarthj
    Member
    Posted 6 years ago #

    I've sorted it by removing !-- and -- as follows.

    before:

    <!-- <?php _e('by') ?> <?php the_author() ?> --></div>

    after:

    <?php _e('by') ?> <?php the_author() ?></div>

    I hope this helps my fellow noobs out there (united we stand)!

  13. kaiserthegreat
    Member
    Posted 5 years ago #

    I can't get it to work in a loop either. I'm creating my own template, so perhaps I'm not including something that is important. It works when uncommented in the Default template, but not in my template, which has the following code:

    <?php if (have_posts()) : ?>
    
       <h2>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
         <?php the_title(); ?>
        </a>
       </h2>
       <small><?php the_time('F jS, Y') ?> by <?php the_author(); ?></small>
    
      <?php else : ?>
    
       Nope!
    
      <?php endif; ?>

    The same code as Default, essentially.

  14. lelandf
    Member
    Posted 5 years ago #

    You're missing a few things in the Loop. You might want to reread this article in the Codex: http://codex.wordpress.org/The_Loop_in_Action#The_Default_Loop

    Try this and see if it works:

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
       <h2>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
         <?php the_title(); ?>
        </a>
       </h2>
       <small><?php the_time('F jS, Y') ?> <?php _e('by') ?> <?php the_author(); ?></small>
    
      <?php endwhile; else : ?>
    
       Nope!
    
      <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags