• sailpilot

    (@sailpilot)


    Just noticed that the-author function does not work when searching for all posts by an author.

    when displaying posts in the loop we have the following line:

    ><?php the_time('l, F jS, Y'); ?> &amp;nbsp <?php the_time( ); ?>  | Author: <?php the_author_posts_link();?> | <?php the_category(', '); ?>
     | <?php comments_popup_link(__('No Comments'), __('1 Comment'), __('% Comments')); ?>

    the author shows up correctly in each post.

    However when clicking on the author’s name in a post the following line is supposed to retrieve all posts by the author. It does retrieve the posts but doe not display the name of the author in the line:

    “You are currently browsing posts by (missing author’s name).”

    <?php /* If this is an author */ } elseif (is_author()) { ?>
    	<div class="notice">You are currently browsing posts by><?php the_author(''); ?>.
    </div>
Viewing 10 replies - 1 through 10 (of 10 total)
  • MichaelH

    (@michaelh)

    The Template Tag, the_author() is intended to be used in The Loop.

    See Author_Templates for more information on displaying the author in a given author archive.

    Thread Starter sailpilot

    (@sailpilot)

    Its strange that it does not work, because we had this working on another blog (different theme) with the exact code I provided above.

    Thread Starter sailpilot

    (@sailpilot)

    also isn’t the retrieval of all posts by an author considered a loop? May be not the main loop but it also cycles.

    asechrest

    (@asechrest)

    As MichaelH mentioned, I don’t think the_author() works unless you use it within a WordPress loop. Yes, the retrieval of all posts by an author is a loop, but unless you use the_author() within that coded loop, it won’t work.

    I don’t think that second segment of code you posted is in a WordPress Loop. If it was, you’d get that display for every post listed. Which I’m sure is not what you want.

    What I think you want is something at the top of the page that displays the author’s name (i.e. outside the Loop). If so, try using something like this before the loop in the template that controls your author display:

    <?php
    			if(isset($_GET['author_name'])) :
    				$curauth = get_userdatabylogin($author_name);
    			else :
    				$curauth = get_userdata(intval($author));
    			endif;
    			?>
    			<?php $auth_ID = $curauth->ID; ?>
    			<div class="left_author">
    			<?php echo get_avatar($curauth->ID, '96' ); ?>
    			<h2>Author: <?php echo $curauth->nickname; ?></h2>
    ?>

    [EDIT] – Don’t cut and paste this code, it’s got my own div names and is probably missing some closing tags. You’ll be able to use most of it, though.

    Thread Starter sailpilot

    (@sailpilot)

    thanks for your response I will give your code a try.

    BTW, the second piece of code I posted is at the top of the index page with several other similar archive retrieval statements (by category, by year,by month,by day and by tag).

    All work (including the retireval by author) on another blog. I am not sure why it does not work on this blog.

    asechrest

    (@asechrest)

    Not sure, you could use a pastebin to post the code for comparison and then link to it here. Myself or others could try taking a look.

    Let us know if that works for you.

    Thread Starter sailpilot

    (@sailpilot)

    I pasted the code from the index.php file into http://wordpress.pastebin.com/m57f70450

    let me know if you see anything πŸ™‚

    asechrest

    (@asechrest)

    I tested that code outside the loop in my author.php and got nothing. Maybe paste the code where you say it’s working?

    Logically and per the codex, the_author() shouldn’t work unless you’re querying a post, so if you use it outside the Loop in an index.php, how does it know what author to display?

    Thread Starter sailpilot

    (@sailpilot)

    here is the one that works, its almost identical. We used it to construct the new blog.

    http://wordpress.pastebin.com/m68792640

    Thread Starter sailpilot

    (@sailpilot)

    I just want to point out that the only difference between the version that is working and the one that is not is that original one displays the author’s name in a line above the retrieved posts, the other one does not.

    Both versions retieve all posts by the author whose name is clicked on in the header line in one of the posts.

    <h6><?php the_time('l, F jS, Y'); ?> &amp;nbsp <?php the_time( ); ?>  | Author: <?php the_author_posts_link();?> | <?php the_category(', '); ?>
     | <?php comments_popup_link(__('No Comments'), __('1 Comment'), __('% Comments')); ?></h6>
Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘The-Author not working’ is closed to new replies.