3 of 4
3
NEW - Redirect Plugin…
Posted: 22 May 2008 06:26 AM   [ Ignore ]   [ # 37 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1130
Joined  02-15-2008

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 | New to ExpressionEngine? Start here!

Profile
 
 
Posted: 22 May 2008 07:26 AM   [ Ignore ]   [ # 38 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

Hi Andy,

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

Download it from here.

File Attachments
redirect_to.zip  (File Size: 2KB - Downloads: 257)
 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 22 May 2008 07:48 AM   [ Ignore ]   [ # 39 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1130
Joined  02-15-2008

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 | New to ExpressionEngine? Start here!

Profile
 
 
Posted: 22 May 2008 07:57 AM   [ Ignore ]   [ # 40 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

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

Profile
 
 
Posted: 22 May 2008 08:03 AM   [ Ignore ]   [ # 41 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

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
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 22 May 2008 08:29 AM   [ Ignore ]   [ # 42 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

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



<?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

Profile
 
 
Posted: 23 May 2008 08:58 AM   [ Ignore ]   [ # 43 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1130
Joined  02-15-2008

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 | New to ExpressionEngine? Start here!

Profile
 
 
Posted: 23 May 2008 01:57 PM   [ Ignore ]   [ # 44 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

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

Profile
 
 
Posted: 24 May 2008 02:52 AM   [ Ignore ]   [ # 45 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

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

Profile
 
 
Posted: 27 May 2008 02:57 AM   [ Ignore ]   [ # 46 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1130
Joined  02-15-2008

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 | New to ExpressionEngine? Start here!

Profile
 
 
Posted: 24 June 2008 07:03 PM   [ Ignore ]   [ # 47 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

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
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 25 June 2008 07:10 AM   [ Ignore ]   [ # 48 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

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

Profile
 
 
Posted: 25 June 2008 07:20 AM   [ Ignore ]   [ # 49 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

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
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 05 July 2008 06:43 PM   [ Ignore ]   [ # 50 ]  
Research Assistant
RankRankRank
Total Posts:  403
Joined  07-04-2007

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}
Profile
 
 
Posted: 05 July 2008 06:58 PM   [ Ignore ]   [ # 51 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

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
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 05 July 2008 07:08 PM   [ Ignore ]   [ # 52 ]  
Research Assistant
RankRankRank
Total Posts:  403
Joined  07-04-2007

Thanks Mark, but unfortunatly I don’t really like using the script option.

I added the redirect to an embedded template and that seems to work. 

I assume there isn’t a way to do it within the same template because of the advanced conditional problems mentioned in this thread?

Profile
 
 
Posted: 05 July 2008 07:13 PM   [ Ignore ]   [ # 53 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10835
Joined  04-15-2006

Hiya,

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.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 20 November 2008 07:19 AM   [ Ignore ]   [ # 54 ]  
Summer Student
Avatar
Total Posts:  19
Joined  01-21-2008

Mark, Laisvunas,

Thanks guys, great plugin and really useful!

Profile
 
 
   
3 of 4
3
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120532 Total Logged-in Users: 76
Total Topics: 126593 Total Anonymous Users: 46
Total Replies: 665537 Total Guests: 378
Total Posts: 792130    
Members ( View Memberlist )
Newest Members:  Rach123Glenn StavaImfaelSMS!persanulandrewknightKittx77AmityBetbulJahhn