Trouble Using template_redirect
-
Hello Wp community. I am normally a web designer (Photoshop, Illustrator and so on ) that has recently come to be forced to learn php and code out Wp themes myself. Which I am only marginally good at. So I want to apologize first off if this topic has been covered to death. I searched a bit and was unable to find a solution so I find myself here asking this.
I am building a theme for a client and for the first time a single – single.php file wont take care of my post display for the different categories I have. Some will be normal “Latest Article” posts that will use the standard single.php file and that works well. I have a couple of categories that will be like real estate listings and they will use a file called saleposts.php which I have included the use of custom fields to list things like bedrooms, bathrooms, address ect… You know like a real estate site, lol. So anyways I have tried this several ways and have not been able to get it to work properly, my listing posts always go to the single.php file instead. So here is how I did it,
First try was like this from a tutorial here The tut I usedfunction my_template() { if (is_category() && get_query_var('cat') == get_cat_id('for-sale')) { include (TEMPLATEPATH . '/salesposts.php'); exit; } } add_action('template_redirect', 'my_template');
This did not work, and I am not sure why….
Then I tried this as a test based on the same tut and it worked but I cant do this for ecery post
function my_template() { if (is_single()) { global $post; if ($post->ID == 881) { include (TEMPLATEPATH . '/salesposts.php'); exit; } } } add_action('template_redirect', 'my_template');
the 881 is the post id. Can anyone help me out with why the first code would not work properly? I am sure that I have everything I need in my header and my functions.php file to make it work properly? Or could I be missing something????
[You’ll reduce the chance of receiving help if you reply to your thread. You remove it from the ‘No replies’ list. Some volunteers proiritise threads on that list over others]
- The topic ‘Trouble Using template_redirect’ is closed to new replies.