Showing author page if user has no post

I have a page with profiles in which people can post or comment on a post. The problem is that if this user chooses to comment instead of post, he or she will not get an author page until it has submitted a post. Is there a way to show the author page anyway? Because I have a function that shows the comments on the author page, but because it has no posts in it, that won’t show too…

I hope someone can help me out.

Read More

PS: I already tried several plugins, but those things didn’t work out.

FYI: this is default behavior of WordPress and I am using the default author.php template which has an “if have posts” loop, if not, loop-no-posts loop. So the author page is not created is there is no post. That is the whole point.

Edit: my code:

        <?php if (have_posts()) : ?>

            <ul><?php
    global $wpdb;
    $user_id = $post->post_author;  
    $where = 'WHERE comment_approved = 1 AND user_id = ' . $user_id ;

    $user = get_userdata($user_id);

    ?>

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

            <?php responsive_entry_before(); ?>
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>       

                <div class="post-entry"><blockquote>
                    <?php if ( has_post_thumbnail()) : ?>
                        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >

                        </a>
                    <?php endif; ?>
                    <?php the_excerpt(); ?>

            </article>    
            <?php responsive_entry_after(); ?>

        <?php 
        endwhile; 

        /* get_template_part( 'loop-nav' ); */

    else : 

        get_template_part( 'loop-no-posts' ); 

    endif; 
    ?>  


<?php
    $args = array(
        'user_id' => $user->ID,
        'number' => 10, // how many comments to retrieve
        'status' => 'approve'
        );

    $comments = get_comments( $args );

    if ( $comments )
    {
        foreach ( $comments as $c )
        {
        $output.= '<a href="'.get_comment_link().'">';
        $output.= get_the_title();
        $output.= '</a>';
        }

        echo $output;
    } else { echo "bla";}?>

</div>

Related posts

1 comment

  1. <?php 
            $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); 
            ?>
            <?php if ( have_posts() ) ?>
            <h2>Posts by <?php echo $curauth->nickname; ?>:</h2>
                <ul>
                <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                    <li>
                        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>">
                        <?php the_title(); ?></a>,
                        <?php the_time('d M Y'); ?> in <?php the_category('&');?>
                    </li>
                <?php endwhile; else: ?>
                    <p><?php _e('No posts by this author.'); ?></p>
                <?php endif; ?>
                </ul>
        <?php
            $args = array(
                'user_id' => $curauth->ID,
                'number' => 10, // how many comments to retrieve
                'status' => 'approve'
                );
    
            $comments = get_comments( $args );
    
            if ( $comments )
            {
                $output.= "<ul>";
                foreach ( $comments as $c )
                {
                $output.= '<li>';
                $output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
                $output.= get_the_title($c->comment_post_ID);
                $output.= '</a>';
                $output.= "</li>n";
                }
                $output.= '</ul>';
    
                echo $output;
            } else { 
                echo "bla";
            }
    ?>
    

    Modified from here.

    Edit: Added OP’s code

Comments are closed.