WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP Rewrite for custom template files (2 posts)

  1. leogermani
    Member
    Posted 4 years ago #

    Hi,

    When I have something in my site that is completly out of the wordpress template hierarchy, I usually parse the URL and then hook into the template_redirect filter to change what template file should be used based on the url. For example when I want mysite.com/project to use projects.php file in my folder.

    I was wondering If a could do this using WP Rewrite class, taking advantage of the built in redirects for paged items and feeds...

    All the examples Ive seen using the wp rewrite class will only change the query string variable sent to the index.php, but will do nothing concerning to choosing the appropriate template file.

    Wonder if anyone has any tips

    cheers

    Leo,,

  2. westondeboer
    Member
    Posted 4 years ago #

    http://kovshenin.com/archives/extending-custom-post-types-in-wordpress-3-0/

    add_action("template_redirect", 'my_template_redirect');
    
    // Template selection
    function my_template_redirect()
    {
    	global $wp;
    	global $wp_query;
    	if ($wp->query_vars["post_type"] == "property")
    	{
    		// Let's look for the property.php template file in the current theme
    		if (have_posts())
    		{
    			include(TEMPLATEPATH . '/property.php');
    			die();
    		}
    		else
    		{
    			$wp_query->is_404 = true;
    		}
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic