Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 11-21-2009, 11:55 AM   #1
I.C.Hope
War Room Member
 
Intrepreneur's Avatar
 
Join Date: Apr 2009
Location: Northern Ireland
Posts: 2,515
Thanks: 446
Thanked 227 Times in 181 Posts
Contact Info
Send a message via Skype™ to Intrepreneur
Default If else if else while if else php for wordpress.

I want to create some code for my wordpress blog sidebar. I want it to display a different offer depending on category. There are over 7 different categories I wish to do this with.

Is it possible to work with if else and while over 7 different variables, the categories in WP being the variable.

If it is I'm willing to pay for someone to create it for me.

Thanks

I want a good keyword researcher, not for min sites but for tech articles. Hit me up if you've got those skillz!
Intrepreneur is offline   Reply With Quote
Old 11-21-2009, 07:53 PM   #2
HyperActive Warrior
 
shaddai's Avatar
 
Join Date: Jan 2009
Posts: 196
Thanks: 7
Thanked 10 Times in 10 Posts
Social Networking View Member's Twitter Profile 
Default Re: If else if else while if else php for wordpress.

Executable PHP widget

That should get you to the point of self coding php in the side bar.

Worthless link...

don't know if it'll help. Maybe enough to get you on the right path.

Of course, I'm so curious now whether it will work or not, I'll have to try it.

“Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic.” -Author Unknown

Resident computer geek. If you need help, don't be afraid to PM here, or DM on Twitter.

Last edited by shaddai; 11-21-2009 at 08:31 PM. Reason: clicked post to quick..worthless link
shaddai is offline   Reply With Quote
Old 11-21-2009, 08:26 PM   #3
HyperActive Warrior
 
shaddai's Avatar
 
Join Date: Jan 2009
Posts: 196
Thanks: 7
Thanked 10 Times in 10 Posts
Social Networking View Member's Twitter Profile 
Default Re: If else if else while if else php for wordpress.

Plaster this code into that plugin & it echo's the current category name.

<?php
foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?>

From there you can drop the echo line, then use standard php if/else statements to get to what you want it to do.

“Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic.” -Author Unknown

Resident computer geek. If you need help, don't be afraid to PM here, or DM on Twitter.
shaddai is offline   Reply With Quote
Old 11-21-2009, 08:26 PM   #4
PHP Author and Programmer
War Room Member
 
Robert Plank's Avatar
 
Join Date: Jul 2002
Location: Turlock, CA, USA.
Posts: 4,024
Blog Entries: 82
Thanks: 28
Thanked 227 Times in 46 Posts
Social Networking View Member's FaceBook Profile  View Member's Twitter Profile  View Member's YouTube Profile
Contact Info
Send a message via ICQ to Robert Plank Send a message via AIM to Robert Plank Send a message via MSN to Robert Plank Send a message via Skype™ to Robert Plank
Default Re: If else if else while if else php for wordpress.

I would use the Widget Logic plugin instead of any exec php stuff.

Create all the widgets with all the offers, and then in the "widget logic" text box underneath each widget, add stuff like this:

in_category("First Category") || is_category("First Category")

Under the next widget add the logic for the other category...

in_category("Next Category") || is_category("Next Category")

And so on.

Robert Plank is offline   Reply With Quote
Old 11-21-2009, 08:38 PM   #5
HyperActive Warrior
 
shaddai's Avatar
 
Join Date: Jan 2009
Posts: 196
Thanks: 7
Thanked 10 Times in 10 Posts
Social Networking View Member's Twitter Profile 
Default Re: If else if else while if else php for wordpress.

Roberts idea works too.. I just had if/else stuck in my head & looked for a quick way to get there.

“Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic.” -Author Unknown

Resident computer geek. If you need help, don't be afraid to PM here, or DM on Twitter.
shaddai is offline   Reply With Quote
Old 11-22-2009, 10:39 AM   #6
I.C.Hope
War Room Member
 
Intrepreneur's Avatar
 
Join Date: Apr 2009
Location: Northern Ireland
Posts: 2,515
Thanks: 446
Thanked 227 Times in 181 Posts
Contact Info
Send a message via Skype™ to Intrepreneur
Default Re: If else if else while if else php for wordpress.

Ok Robert I'll take a look and see what I can do.

Thanks.

I want a good keyword researcher, not for min sites but for tech articles. Hit me up if you've got those skillz!
Intrepreneur is offline   Reply With Quote
Old 11-23-2009, 04:47 AM   #7
HyperActive Warrior
War Room Member
 
webtrix's Avatar
 
Join Date: Oct 2009
Location: SE Europe
Posts: 112
Thanks: 8
Thanked 8 Times in 8 Posts
Social Networking View Member's Twitter Profile 
Contact Info
Send a message via Skype™ to webtrix
Default Re: If else if else while if else php for wordpress.

You can do this very easily yourself, try this:

Code:
<?php if (is_category('Category A')) { ?>

<p>Offers for category A</p>

<?php } elseif (is_category('Category B')) { ?>

<p>Offers for category B</p>
<?php } else { ?>

<p>This is some generic text to describe all other category pages, 
I could be left blank</p>
<?php } ?>
Source: Category Templates WordPress Codex
webtrix is offline   Reply With Quote
Old 11-24-2009, 05:46 PM   #8
Advanced Warrior
War Room Member
 
Ken Durham's Avatar
 
Join Date: Jun 2009
Location: Chesterton, IN
Posts: 923
Thanks: 129
Thanked 193 Times in 153 Posts
Default Re: If else if else while if else php for wordpress.

Usually when dealing with this style you would use a switch/case style of programming:

switch ($category_variable) {
case "a":
do something;
break;

case "b":
do something;
break;

default;
do something if noting matches or leave this out;
break;

}

Webmaster Services
List Your Wealth Building Systems and Services for Free

Insanity is doing the same thing over and over and expecting a different result ~ Einstein
Insanity is doing the same thing over and over and never getting the same results ~ Ken

Ken Durham is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
dor, php, wordpress

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 05:10 AM.