• I need to create a Gallery page under a template called Gallery.php that rests in the URL as a subpage to the Author.php template like so:

    example.com/author/thirdofthetimelords/gallery

    I have a shortcode from Envira which I can implement into Gallery.php that will pull the nickname of the author in question and provide the album of every picture they have been tagged in. I want this page to populate automatically, similar to the Author.php page, because we have 30+ authors and I don’t have time to create a gallery for each one of them. I simply need help setting up Gallery.php to go where I need it to and have the permalink I need it to have.

    I have been spending the past 6 hours researching template hierarchies, endpoints, and queries and just simply can’t seem to find a way to set this up. Any help would be greatly appreciated. Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    I would like to help with some of this, which is to make example.com/author/thirdofthetimelords/gallery functional.

    Add the following code to your child theme’s functions file, and then go to settings > permalink scroll down and save to flush the rewrite rules.

    add_action('init', function() {
    	global $wp_rewrite;
    	add_rewrite_rule(
    		$wp_rewrite->author_base . '/([^/]+)/gallery/?$',
    		'index.php?author_name=$matches[1]&_auth_gal=1',
    		'top'
    	);
    });
    
    add_filter('query_vars', function($vars) {
    	$vars[] = "_auth_gal";
    	return $vars;
    });
    
    /**
      * tells whether we are in the author/^/gallery/ screen
      * use get_the_author_meta( 'ID' ) to get the author ID
      *
      * @return bool true|false
      */
    
    function se_is_author_gallery() { return "1" == get_query_var('_auth_gal'); }

    After that, you can use se_is_author_gallery() function to tell if we are viewing the gallery of certain author. To get the author ID, simply use get_the_author_meta( 'ID' ).. Maybe you’re going for a custom author template in this case..

    I hope that helps.
    Samuel

    Thread Starter kittensightings

    (@kittensightings)

    Thank you very much for the response!

    I tried to follow a very similar support post from someone trying to create a similar template but called “Liked-Posts”, and I am running into the same problem.

    I’m not using the child theme, I’ve been modifying the normal theme. Is this where I’m running into problems?

    I followed the directions, and I can get example.com/author/thirdofthetimelords/gallery to show up in the URL, but it’s simply the Author.php template and not the Gallery.php template. So something is obviously working, and something is not. Do you have any idea what might be the problem?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Creating a subpage to the Author template’ is closed to new replies.