Just tried out the new version that you have provided Laisvunas (btw is that your name or a nickname?) and it all works brilliantly, well done.
When I get home tonight I will update the original plugin to have your name in there mentioned a lot more! I will also update the instructions in the plugin and in the first post of this thread to reflect your new add-ons and credit you there too of course!
Just out of interest though (and I probably missed this in the thread somewhere) why does it work with {if} conditionals when you use a javascript location redirect but it won’t work with a PHP one?
Thanks again for the exceptionally quick work on that one and helping out like that. Much appreciated.
Laisvunas is my real name. Sound strange those all names from new member-states for English ears aren’t they?
Just out of interest though (and I probably missed this in the thread somewhere) why does it work with {if} conditionals when you use a javascript location redirect but it won’t work with a PHP one?
I do not have exact answer on this but it seems that PHP redirect can only occur before http headers were sent; in contrast javascript redirect can occur anytime.
When posting modified version of the Redirect To plugin I forgot to include udated usage() function. Here is it; it’s text may also be useful when writing instructions.
function usage() { ob_start(); ?>
This plugin is exceptionally simple to use. Place the following tag on any template as shown below :
Using full URL - useful for external sites. {exp:redirect_to location="http://www.yahoo.com"}
or using paths instead - useful for internal links. {exp:redirect_to location="news/detail/news_story"}
By default PHP redirection will be performed. If PHP redirection does not work, use javascript redirection by adding method="script" parameter. {exp:redirect_to location="news/detail/news_story" method="script"}
If it is impossible by usual means to check if condition for redirection was met or not you can check it by wrapping the code expressing condition by {exp:redirect_to}{/exp:redirect_to} tags. Redirection will be performed if the code wrapped by {exp:redirect_to}{/exp:redirect_to} tags will produce no output. {exp:redirect_to location="my_template_group/my_template" method="script"} {exp:query sql="SELECT title FROM exp_weblog_titles WHERE weblog_id = '5' AND url_title ='My title'"} {title} {/exp:query} {/exp:redirect_to}
If you want that redirection would be performed on condition that certain output were produced, you should enter expected string as a value of "tagdata" parameter. Then the redirection will be performed if the string entered as "tagdata" parameter value and output of the code wrapped by {exp:redirect_to}{/exp:redirect_to} tags are identical. (Tabs, spaces and new line characters will be stripped.) In example below redirect will occur if {exp:query tag} will produce string "1". {exp:redirect_to location="my_template_group/my_template" tagdata="1" method="script"} {exp:query sql="SELECT title FROM exp_weblog_titles WHERE weblog_id = '5' AND url_title ='My title'"} {total_results} {/exp:query} {/exp:redirect_to}
Thanks for the quick response there Laisvunas. Still not working for me I’m afraid. Here’s the exact code I’m running, complete with comments - if there’s anything obvious in there that you can spot, it’d be helpful. I’m using single quotes on my exp:redirect_to location call to cater for the categories call in there, but it does the same thing with double quotes.
{if segment_1 == ""} {exp:weblog:entries weblog="home" dynamic="off" disable="member_data|trackbacks" limit="1"} //do some stuff {/exp:weblog:entries} {if:else} <!--GET ALL CASESTUDIES BASED ON CURRENT PAGE--> {exp:weblog:entries weblog="casestudy" disable="member_data|trackbacks"} <!--IF THERES ONLY ONE RESULT...--> {if total_results == 1} <!--...REDIRECT TO THE ACTUAL CASESTUDY PAGE--> {exp:redirect_to location='/casestudy/{categories show_group="4"}{category_url_title}{/categories}/{url_title}' tagdata="1" method="script"}{/exp:redirect} {/if} {/exp:weblog:entries} {/if}
Redirect part of your code does not comply with usage instructions of Redirect plugin. If you want to test complicated condition you shoud *wrap* the code expresssing that condition with {exp:redirect_to){/exp:redirect_to} tag pair. In your code {exp:redirect_to){/exp:redirect_to} tag pair does not wrap anything.
Correct code would be this:
{if segment_1 == ""} {exp:weblog:entries weblog="home" dynamic="off" disable="member_data|trackbacks" limit="1"} //do some stuff {/exp:weblog:entries} {if:else} <!--GET ALL CASESTUDIES BASED ON CURRENT PAGE--> <!--IF THERES ONLY ONE RESULT...--> <!--...REDIRECT TO THE ACTUAL CASESTUDY PAGE--> {exp:redirect_to location='/casestudy/{categories show_group="4"}{category_url_title}{/categories}/{url_title}' tagdata="1" method="script"} {exp:weblog:entries weblog="casestudy" disable="member_data|trackbacks"} {total_results} {/exp:weblog:entries} {/exp:redirect_to} {/if}
Redirect should be performed if {exp:weblog:entries weblog=“casestudy” disable=“member_data|trackbacks”} tag outputs the string “1”, that is, when there is only one entry found.
Here is another piece of code which also should achieve what you want:
{if segment_1 == ""} {exp:weblog:entries weblog="home" dynamic="off" disable="member_data|trackbacks" limit="1"} //do some stuff {/exp:weblog:entries} {if:else} <!--GET ALL CASESTUDIES BASED ON CURRENT PAGE--> {exp:weblog:entries weblog="casestudy" disable="member_data|trackbacks"} <!--IF THERES ONLY ONE RESULT...--> {if total_results == 1} <!--...REDIRECT TO THE ACTUAL CASESTUDY PAGE--> {exp:redirect_to location='/casestudy/{categories show_group="4"}{category_url_title}{/categories}/{url_title}' method="script"} {/if} {/exp:weblog:entries} {/if}
Ahha, I see what I did. That works, thanks muchly….however the problem I have now is that I don’t want to use a javascript redirect if I can help it.
If I remove the method=“script” section, it redirects regardless of total_results. As this chunk of code is at the top of the page before (as far as I can tell) any header information is written, I would have thought I could do a PHP redirect. :(
Right then. I have just uploaded the newest version of this to the first post and I have to make a public apology on the forums here to Laisvunas. He did a lot of work on this plugin adding in the new features and I went and added them into the plugin but forgot to upload it to the thread so for that I really do apologise.
Hopefully I have done it all correct and it should work as advertised. I will leave the original plugin in the first thread as well though just in case I have coded anything wrong. It’s just after 1 here and I am just a little bushed now!!
I’m trying to use this to forward certain members to an alternative start page, but i’m having the problem mentioned here before that it forwards if the conditional is met or not. Any ideas how to fix this?
{if member_group=="1" OR member_group=="5" OR member_group=="6"} {exp:redirect_to location="http://www.example.com/index.php/blog/"} {/if}
Yep the problem arises as I think it all had something to do with not being able to re-direct using a PHP method after headers have already been sent so the only other way is to either use an embed as you have or use a Javascript method instead.