Jump to content
Sign in to follow this  
mcbenton

How to determine current template?

Recommended Posts

mcbenton

I want to output custom content on author pages. I installed the Pagelines Customize plugin and have written a filter that will allow me to add content where I want:

add_filter( 'pagelines_before_postsinfo', 'my_author_info' );
	function my_author_info() {
	    if ( is_page_template( 'author.php' ) ) {
	        // I will output my content here
	    }
	}

However, PageLines doesn't use author.php, but I'm having trouble figuring out how to detect whether or not I'm on an author page or not. Any suggestions? Thanks, Morgan

Share this post


Link to post
Share on other sites
mcbenton
I think I've found one solution, but I'd love it if someone had a better one. Using the info from the [url="http://codex.wordpress.org/Author_Templates"]WP Author Templates documentation[/url]: [code]add_filter( 'pagelines_before_postsinfo', 'my_author_info' ); function my_author_info() { // is this an author page? $ca = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) ); if ( $ca instanceof WP_User ) { // output my code here } }[/code] This appears to do what I want, but I haven't tested it to see if it actually appears on other pages or not.

Share this post


Link to post
Share on other sites
Simon
http://codex.wordpress.org/Function_Reference/is_author

Share this post


Link to post
Share on other sites
mcbenton
Gee. I feel dumb. I think I looked at that function and rejected it because it looked like you had to have a specific author ID known ahead of time to use it. Obviously didn't read down far enough. Thanks, Simon!

Share this post


Link to post
Share on other sites
Simon
Ha no probs, wordpress nearly always has an in built function for thee things.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×