• I’ve been searching around for a solution to this one but am having no joy.

    I’m developing a website for a record label. Each artist on the record label will be an author on the site and is allowed to post articles etc. This is convenient as it allows each artist to edit their profile and this is what will appear on their “Artist Page” on the site.

    So, an example of a page that this works on is:

    https://devel.invisibleagent.com/author/ebauche/

    I have attributed one test post to this author and his profile appears and correctly uses the author.php template file in my theme.

    However for all artists that don’t have any posts attributed to them, I just get a 404 page. It was suggested here that having an author.php template file sorts the issue, but it clearly doesn’t.

    So if you go to another author page on the site you get the 404.php template.

    I would like to avoid having to actually create a “My first post” for each artist on the site, as I don’t think this will look very professional.

    I had toyed with incorporating the artist bio’s into another page on the site, https://devel.invisibleagent.com/artists/ but this makes for a very long page, and after a lot of playing with accordion affects we’ve decided that what we really want is essentially a list of authors and their photos which links through to their profile.

    Is there any way to force WordPress to display the /author/ page when they don’t have any posts?

    If not, then I will have to look at some fun and games with PHP and possibly a link structure like /artists/?artist=ebauche

    I think something like this would allow me to code my artists-page.php template to grab that variable and then only display the artist listed, their picture, their bio, and only show posts if they have any. However I’ll have to test this out some..

    Maybe something like the below (my plain english type code again ??

    $artist = NULL;
    $artist = $_GET['artist'];
    if (! empty ($artist) ) {
      // get artist info from database (might need to use ID instead of nickname to enable this
      if artist id exists {
        display bio, photo, if posts show them;
      } else {
        display error message and fall through to display all artists;
        }
    } else {
    if the url doesn't have the additional ?artist=
    then display basic page with all artist photos and links to ?artist=ID
    }

    That would probably do it – I’m sure it’s workable, but obviously it would be great if I could just use the author.php template in all cases, posts or not!

    By the way, thanks to Kaf Oseo (https://szub.net/) for his excellent “All Authors Template” which I’m using on this artists page. Very nice stuff.. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter alexleonard

    (@alexleonard)

    Oh, by the way, I’ve looked at the Aleph plugin, which looks like it might get around this, but it feels like a lot of extra functionality and complexity that I don’t need.

    did you ever find a solution to this problem?

    I solved this by adding an action on the “template_redirect” chain:

    function member_template_redirect()
       {
          global $wp_query;
    
          if( array_key_exists('author_name', $wp_query->query_vars) && !empty($wp_query->query_vars['author_name']) )
          {
             global $member;
             $member = new WP_User( $wp_query->query_vars["author_name"] );
             if( $member )
             {
                include( TEMPLATEPATH . "/member.php" );
                exit;
             }
          }
       }
    
       add_action( 'template_redirect', 'member_template_redirect' );

    This calls my “member.php” template with whatever query results the standard author handling came up with, plus a WP_User object for the requested member in the $member variable. The user record data is in $member->data, plus you can check capabilities using $member->has_cap(). If the member doesn’t exist, it should still fall through to the 404 handler.

    Finally, this code isn’t verbatim from my site, so I can’t promise it will work perfectly. Use at your own risk.

    Thread Starter alexleonard

    (@alexleonard)

    Thanks for the response chris. I haven’t been working on that site for a little while so I’m a little out of touch on what I was trying to sort exactly, but I should be looking at it again in the coming days.

    I’ll report back here on my findings.

    powtac

    (@powtac)

    Hi alexleonard,
    I created a plugin which prevents the 404 at the authors page, when the author has no posts:

    https://www.ads-software.com/extend/plugins/show-authors-without-posts/

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Author Page with no posts’ is closed to new replies.