Page 2 of 4
Re: Conditional redirect to another page
Posted:
August 9th, 2011, 9:44 pm
by cassel
Well, yes and no. I tried disabling Exec-PHP; didn't work. At Headway theme support forum, i was suggested to disable s2Member so i could at least edit the code, but that didn't work either. In the end, i had to scratch the page and start all over again. Lucky for me it was just a test page so, nothing was really lost.
Right now, before i use the conditional
redirect (which seemed to work!), i need to figure out why i am getting underline of a different color than text in links. I know it has nothing to do with the theme, so i am a bit at loss (since i never edited the CSS file).
http://scrapbookcampus.com/testpage(the white headers have black underline... weird). If you have any suggestion on that, i am all ear, but if not, i'll have to address that FIRST and the conditional
redirect AFTER.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 1:38 pm
by Cristián Lávaque
That's because a text-decoration:underline; in line 44 of
http://scrapbookcampus.com/wp-content/t ... 1312942086You can use Firebug to spot this kind of things.
http://getfirebug.com/About the redirection, instead of the header approach you used earlier, you can try JavaScript, like:
- Code: Select all
<script type="text/javascript">window.location = 'http://scrapbookcampus.com/basic-tutorials-for-scrapbooking-with-paintshop-pro/';</script>
I hope that helps.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 1:57 pm
by cassel
For the text decoration, somehow i cannot access that link (i get a jumbled up text instead of an expected tidy format). I am not even sure what it looks like and what it should look like (i barely know html). I would have thought that the default value would be to have an underline the same color as the text, especially since i never messed with that file.
Firebug: i was told about that, but i will have to study how to use it because when i was trying to figure out something else, i would not get information on what i was looking for. That is on my to-do list.
For the Java script, does that replace or go with the conditionals (since i want only paying members to be redirected)? And where do i put that? I know even less about Java than i know about HTML (shoudl give you an idea that i know nothing!)
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 2:01 pm
by Cristián Lávaque
Yeah, you'd use that inside the condition or it'll happen for everyone loading the page. Use the HTML editor when you add it, the Visual one will mess it up.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 2:12 pm
by cassel
I am not using the HMTL editor or the visual one for this since i am using leafs from Headway Theme. That is why i was locked out before without access through the dashboard. But i`ll try that inside a leaf, using the code within the conditionals. I`ll let you know how it works.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 4:34 pm
by Cristián Lávaque
OK.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 5:43 pm
by Bruce C
Cristián Lávaque wrote:- Code: Select all
<script type="text/javascript">window.location = 'http://scrapbookcampus.com/basic-tutorials-for-scrapbooking-with-paintshop-pro/';</script>
Just a note, whenever a Javascript
redirect is put through, it loads the header, and sometimes the contents of the page before redirecting, which is why I posted the php
redirect, which loads before the page, therefore it causes less lag.
However, Cristián is correct. That will work also.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 6:18 pm
by Cristián Lávaque
But using header in the post's body I feel you risk some content having been served before the new header and getting an error. Or does WP start serving page later than the point with the redirection header in the post's body?
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 6:30 pm
by cassel
I'll have to test that since i was not planning on posting in the WP page, but inside a HT leaf!
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 6:36 pm
by Bruce C
It appears that as long as the
redirect of PHP is in the <head> tag it does not matter if anything is above it. It is automatically done first.
If you post this into a WordPress post, or just a .php file, it still works the same.
- Code: Select all
<body>
Body Text
</body>
<head>
<?php echo "hello"; ?>
<?php header( 'Location: http://google.com/' ) ; ?>
</head>
None of the text shows up, and it redirects as always.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 6:41 pm
by cassel
Silly question: what does that line mean:
<?php echo "hello"; ?>
Is it to be used as is, or only a placeholder?
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 6:46 pm
by Bruce C
- Code: Select all
<?php echo "hello" ?>
is the same thing as just typing hello in a html page. Just to show that code before the
redirect does not affect it.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 7:03 pm
by cassel
So do i NEED that line?? (i am more confused now!)
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 7:10 pm
by Cristián Lávaque
No, that "hello" was just an example to show me that he could have output before the header line, without getting an error.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 7:13 pm
by Bruce C
No, those past few posts were just to assure that the PHP
redirect was safe enough.
This code:
- Code: Select all
<head>
[s2If current_user_can(access_s2member_ccap_basic)]<?php header( 'Location: http://scrapbookcampus.com/basic-tutorials-for-scrapbooking-with-paintshop-pro/' ) ; ?>
[/_s2if]
[s2If !current_user_can(access_s2member_ccap_basic)
[/s2If]
</head>
Should be all you need. Or, as Christian said, you could remove the <head> portion, and instead use:
- Code: Select all
[s2If current_user_can(access_s2member_ccap_basic)]
<script type="text/javascript">window.location = 'http://scrapbookcampus.com/basic-tutorials-for-scrapbooking-with-paintshop-pro/';</script>
[/s2If]
[s2If !current_user_can("access_s2member_ccap_basic")
[/s2If]
However, this will cause the contents of your page to first view, as it is NOT loaded before the contents of your page. This should be the only difference.
EDIT:
Took out quotes around access_s2member_ccap_basic.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 7:22 pm
by cassel
Well, i will test it and let you know if it does what i want it to do.
Re: Conditional redirect to another page
Posted:
August 10th, 2011, 7:23 pm
by Bruce C
OK, thanks!
Re: Conditional redirect to another page
Posted:
August 13th, 2011, 8:58 pm
by cassel
As i am testing, i do not get it to do what i want. Here is the complete code
- Code: Select all
[s2If current_user_can("access_s2member_ccap_basic")]<script type="text/javascript">window.location = http://scrapbookcampus.com/welcome-to-the-basic-scrapping-course/';</script>
[/s2If]
[s2If !current_user_can("access_s2member_ccap_basic")]
if you see this, it means you dont have access to the student area and therefore, i will try to sell you the course.... hahaha</br></br>
[/s2If]
and it is on this page:
http://scrapbookcampus.com/test-redirectIf you are not a member or not logged in, you will see a little message saying so. However, if you ARE a logged in member with Basic access, it still stays on the same page. I tested it with a user Member1 (pw: Member1). I know that as an admin, i am not redirected either.
Did i miss something along the way?
Re: Conditional redirect to another page
Posted:
August 13th, 2011, 9:28 pm
by Bruce C
Ah, silly me converting from the original php code.
Just take out the quotes around access_s2member_ccap_basic.
Re: Conditional redirect to another page
Posted:
August 13th, 2011, 9:33 pm
by cassel
Almost there. Now, as i am logged in and should have access, i dont see that text anymore, but i am not redirected either. Anything else i am missing?
Re: Conditional redirect to another page
Posted:
August 13th, 2011, 9:38 pm
by Bruce C
The beginning quote around your redirection link is missing.
Re: Conditional redirect to another page
Posted:
August 13th, 2011, 9:39 pm
by Bruce C
Wait, before doing that, I would consider using the <?php style tags, so that you do not get locked out.
Use this instead:
- Code: Select all
<?php if (current_user_can('access_s2member_ccaps_basic') && !current_user_can('administrator'))
{ ?>
<script type="text/javascript">window.location = 'http://scrapbookcampus.com/basic-tutorials-for-scrapbooking-with-paintshop-pro/';</script>
<?php } else {?>
<?php } ?>
What this will do is not
redirect you if you are an administator, so you will not be locked out.
Re: Conditional redirect to another page
Posted:
August 13th, 2011, 9:51 pm
by cassel
Hum.... still not working. One thing i also notice is that if i copy the code, in wp it just jumbles it all up, without the formatting. I wonder if it can be a problem?
Re: Conditional redirect to another page
Posted:
August 13th, 2011, 9:54 pm
by Bruce C
No, I fixed that code. Sorry, I was just trying not to get you locked out. lol.
That edited code will work now.
Re: Conditional redirect to another page
Posted:
August 13th, 2011, 9:57 pm
by cassel
You lost me there. Don't i have to put the viewable content in that code or is it only to put above any content?