EllisLab text mark
Advanced Search
3 of 5
3
   
NEW - Redirect Plugin…
Posted: 22 May 2008 08:26 AM   [ Ignore ]   [ # 37 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-15
1085 posts

No need to apologise, you have no obligation to fill. I’ll have a go at adding Laisvunas’s code in there, should be fun.

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter

 
Posted: 22 May 2008 09:26 AM   [ Ignore ]   [ # 38 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-02
982 posts

Hi Andy,

I have already a version of Redirect To plugin with all new code added.

Download it from here.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

 
Posted: 22 May 2008 09:48 AM   [ Ignore ]   [ # 39 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-15
1085 posts

Ta. I uploaded it but still doesn’t seem to work. Here’s my code:

{exp:weblog:entries weblog="casestudy" disable="member_data|trackbacks"}
    {if total_results 
== 1}
        {exp
:redirect_to location="/casestudy/{categories show_group="4"}{category_url_title}{/categories}/{url_title}"}
    {
/if}
{
/exp:weblog:entries} 

This redirects to a single entry even if total_results is greater than 1.

In fact, this code renders the word ‘YES’ to the screen so the conditional is certainly working.

{exp:weblog:entries weblog="casestudy" disable="member_data|trackbacks"}
    {if total_results 
== 1}
        YES
        {
!--exp:redirect_to location="/casestudy/{categories show_group="4"}{category_url_title}{/categories}/{url_title}"--}
    {
/if}
{
/exp:weblog:entries} 
 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter

 
Posted: 22 May 2008 09:57 AM   [ Ignore ]   [ # 40 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-02
982 posts

Hi Andy,

having installed modified plugin you can use this code:

{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} 

It should perform a redirect if your condition is met.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

 
Posted: 22 May 2008 10:03 AM   [ Ignore ]   [ # 41 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts

Hiya,

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! wink

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.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 22 May 2008 10:29 AM   [ Ignore ]   [ # 42 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-02
982 posts

Hi Mark,

Laisvunas is my real name. Sound strange those all names from new member-states for English ears aren’t they? surprised

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 producedyou should 
enter expected string 
as a value of "tagdata"  parameterThen 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. (Tabsspaces 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}

 

<?php
$buffer 
ob_get_contents();
    
ob_end_clean(); 

return 
$buffer;
 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

 
Posted: 23 May 2008 10:58 AM   [ Ignore ]   [ # 43 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-15
1085 posts

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} 
 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter

 
Posted: 23 May 2008 03:57 PM   [ Ignore ]   [ # 44 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-02
982 posts

Hi Andy,

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.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

 
Posted: 24 May 2008 04:52 AM   [ Ignore ]   [ # 45 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-02
982 posts

Hi Andy,

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} 
 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

 
Posted: 27 May 2008 04:57 AM   [ Ignore ]   [ # 46 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-15
1085 posts

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. :(

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter

 
Posted: 24 June 2008 09:03 PM   [ Ignore ]   [ # 47 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts

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!! wink

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 25 June 2008 09:10 AM   [ Ignore ]   [ # 48 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-02
982 posts

Hi Mark,

No need for any apologies. It was a pleasure to code some new features for your plugin.

Thanks for uploading new version.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

 
Posted: 25 June 2008 09:20 AM   [ Ignore ]   [ # 49 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts

No problem and thanks again for all the help on this one. This community really is the best I have ever ever ever ever come across.

Hope you’re having a great week.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 05 July 2008 08:43 PM   [ Ignore ]   [ # 50 ]   [ Rating: 0 ]
Joined: 2007-07-04
459 posts

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} 
 
Posted: 05 July 2008 08:58 PM   [ Ignore ]   [ # 51 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts

Hiya,

Try this instead with V1.2 :

{if member_group == "1" OR member_group == "5" OR member_group == "6"}
{exp
:redirect_to location="http://www.yahoo.com" method="script"}
{if
:else}
<p>Not redirecting you this time!!</p>
{/if} 

That should hopefully do it for you?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
3 of 5
3