• Resolved laurazucchetti

    (@laurazucchetti)


    I have created an author page so when an authors name is clicked they will go to the author page that firstly says:

    Viewing all posts by abc_author:

    then displays posts…

    This all works great however for some reason it repeats the Viewing all posts by abc_author: at the top of every post instead of just appearing once at the top of the page. Here’s my template code:

    <?php get_header(); ?>

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <?php
    if(isset($_GET['author_name'])) :
    $curauth = get_userdatabylogin($_GET['author_name']);
    else :
    $curauth = get_userdata($_GET['author']);
    endif;
    ?>

    <h2 class="author">Viewing all posts by <?php echo $curauth->first_name; ?>:</h2>

    <div id="post-<?php the_ID(); ?>" class="entry"> etc etc etc

    Does anyone know how I can stop this repeating head and just get it to display once?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You placed your “Viewing all posts by” header in The Loop for your posts, so it will repeat with each post that appears.

    To fix, move this:

    <?php
    if(isset($_GET['author_name'])) :
    $curauth = get_userdatabylogin($_GET['author_name']);
    else :
    $curauth = get_userdata($_GET['author']);
    endif;
    ?>

    <h2 class="author">Viewing all posts by <?php echo $curauth->first_name; ?>:</h2>

    to just above where The Loop starts:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    Thread Starter laurazucchetti

    (@laurazucchetti)

    Thanks so much that fixed it. 😀 Phew.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘author pages’ is closed to new replies.