• Hi everyone,

    I am building a website that has many guest authors, but there is only one admin account that publishes it all.

    Instead of creating multiple accounts, which would be impractical due to the high number of authors, I added a custom field called guest authors to every post and I managed to displayed it dinamically in the frontend.

    Later, to change the author in the WordPress panel to show the guest author’s name, I added this to my functions.php:

    add_filter( 'the_author', 'guest_author_name' );
    add_filter( 'get_the_author_display_name', 'guest_author_name' );
     
    function guest_author_name( $name ) {
        global $post;
     
        $author = get_post_meta( $post->ID, 'guest-author', true );
     
        if ( $author )
        $name = $author;
        return $name;
    }

    But the problem is that there is not an individual page for each of the guest authors. Is there a way to create via php an author page for each guest author, automatically?

    Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You could create a page that contains the author page content and layout you want. The dynamic portions can be handled by way of shortcodes, custom blocks, or custom page template.

    The author’s name, slug, or ID could be passed as an URL query string or custom permalink structure. For example:
    example.com/guest-author/?guest=bcworkz
    or
    example.com/guest-author/bcworkz/ (the 1st example is easier to implement)

    For the dynamic content, I suggest a custom page template. If you name the template page-guest-author.php (or whatever page slug you assign to the page), then that file will be used to generate content. The template could query for author data, or simply query for the posts they had authored and run a standard loop to display them. When you create custom templates, it’s best to create a child theme in which to keep them.

    If you just intend to query for their posts and there’s no other author data to display, you could simply alter the page’s main query through the “pre_get_posts” action and let the normal template loop output the results.

    FWIW, I don’t think it’s a good idea to have one (or even several) shared guest author account. WP doesn’t care how many user accounts there are. I don’t have access to all forum member data, but I guarantee there are far more registered users here than you will ever see on your site ?? I once managed computer classes for a bunch of disadvantaged youth and thought the same as you are — there are far too many kids to manage each child as a separate account (self registration wasn’t possible, I had to create each account). They’re just kids, they can share a few accounts. That was a big mistake! I gained nothing in doing so and the scheme was just a big headache.

    No doubt some people are reluctant to register out of privacy concerns. But it’s a minimal requirement in order to gain the privilege of being able to write for your site. Registration can be rigged up so an email isn’t required, if that’s the concern. You don’t want to allow any random person to write posts without some kind of accountability.

    Just sayin’. It’s your site though, do as you wish ??

    Thread Starter revistausina

    (@revistausina)

    Thanks lot. I will take your advice into consideration to make different user accounts. Meanwhile, I am going to try to implement your idea of passing the Author’s name as a URL query string. Thanks so much again

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Create custom author page’ is closed to new replies.