Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   If else if else while if else php for wordpress. (https://www.warriorforum.com/programming/147208-if-else-if-else-while-if-else-php-wordpress.html)

Intrepreneur 21st November 2009 11:55 AM

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

shaddai 21st November 2009 07:53 PM

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.

shaddai 21st November 2009 08:26 PM

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.

Robert Plank 21st November 2009 08:26 PM

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.

shaddai 21st November 2009 08:38 PM

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.

Intrepreneur 22nd November 2009 10:39 AM

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.

webtrix 23rd November 2009 04:47 AM

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

Ken Durham 24th November 2009 05:46 PM

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;

}


All times are GMT -6. The time now is 10:12 PM.