risingtalenttv Posted May 14, 2010 Share Posted May 14, 2010 Hi, I have a simple if elseif statement set up right now to change one of my sidebar items based on the presence of posts filed under a certain array of tags, but I dont want it to change the item on the homepage (which displays the two most recent posts...) So, I am wondering if there is any kind of exception rule I can give it so it knows not to apply on the front page? ...or is there a better way to change the sidebar item based on categories/tags? I use Wordpress CMS btw. Link to comment Share on other sites More sharing options...
boen_robot Posted May 14, 2010 Share Posted May 14, 2010 If you can set up a variable upon entering the home page, you can check for the presence of that variable.If you can't do that, you can simply see if $_SERVER['REQUEST_URI'] is the same as the one on your home page. I'm guessing that would mean "/", but if your "homepage" is actually at, say, "example.com/blog/", the home request URI will be "/blog". Link to comment Share on other sites More sharing options...
risingtalenttv Posted May 15, 2010 Author Share Posted May 15, 2010 If you can set up a variable upon entering the home page, you can check for the presence of that variable.If you can't do that, you can simply see if $_SERVER['REQUEST_URI'] is the same as the one on your home page. I'm guessing that would mean "/", but if your "homepage" is actually at, say, "example.com/blog/", the home request URI will be "/blog".I dont quite follow you... I understand the idea behind what you mean. By associating a variable to the homepage I could use it in the current elseif statement, but what is the best way to go about doing that. I would consider myself a beginner - intermediate coder... so please dumb it down for me Thanks. Link to comment Share on other sites More sharing options...
boen_robot Posted May 15, 2010 Share Posted May 15, 2010 You can chain conditions in a single if() by using the "&&" (logical "and") operator. So, for example, in your home page, you may have, say: $disableSidebar = true; and in your actual condition for showing the sidebar, you can have if ( (!isset($disableSidebar) || $disableSidebar !== true) && whatever_the_other_condition_is) {Which says that if the variable is not present, or has a value different than true, proceed with the other check, and if all is true, display the sidebar.It's hard for me to be any more specific without any actual code. Link to comment Share on other sites More sharing options...
risingtalenttv Posted May 16, 2010 Author Share Posted May 16, 2010 Ok boen I gotcha now, but I still don't see how this can be used as an efficient solution because I can use that to tell it to display on the homepage (containing that variable) but how can I tell it to ONLY enable when the variable is NOT present? The only way I see that working is if I applied the variable to every page other than the homepage. Maybe im missing something.Here is the example of the code I'm using if this helps.Code for displaying side box 1: <?php /* If this is a category archive */ if ( is_front_page() ) { } elseif ( is_page() ) { } elseif ( is_404() ) { } elseif ( is_tag(array(39,40,42,46,47,48,49,50,51,52,53,54,55,56,57)) ) { } elseif ( in_category(array(1,16,18,44,45)) ){ ?> Code for displaying side box 2: <?php if ( is_tag(array(25,26,27,28,29,30,31,32,33,34,35,36,37,38,43)) ) { } elseif ( in_category('17') ){ ?> Whats displaying now: Either Box 1 or Box 2 are displaying on their respective pages, but Box 2 is displaying (because post 2 fits its criteria) on the homepage/index where I would like to see Box 1 permanently. Link to comment Share on other sites More sharing options...
risingtalenttv Posted May 17, 2010 Author Share Posted May 17, 2010 BUMP pls Link to comment Share on other sites More sharing options...
justsomeguy Posted May 17, 2010 Share Posted May 17, 2010 I'm not quite sure what you're doing with the elseifs, but it sounds like you just need to learn to use the logical operators. You could replace this, for example: <?php /* If this is a category archive */ if ( is_front_page() ) { } elseif ( is_page() ) { } elseif ( is_404() ) { } elseif ( is_tag(array(39,40,42,46,47,48,49,50,51,52,53,54,55,56,57)) ) { } elseif ( in_category(array(1,16,18,44,45)) ){ with this: if (!is_front_page() && !is_page() && !is_404() && !is_tag(array(39,40,42,46,47,48,49,50,51,52,53,54,55,56,57)) && in_category(array(1,16,18,44,45))){} Link to comment Share on other sites More sharing options...
risingtalenttv Posted May 17, 2010 Author Share Posted May 17, 2010 YES! I finally found and learned what I was looking for! LOGICAL OPERATORS FTW! I knew there had to be a way to do like "and" "or" and "not"...I took all that overly complicated code and condensed it to: <?php /* Display Top Rated Articles */ if (is_front_page() || !in_category('17')) { ?> <?php /* Display Critiques and Reviews */ if (in_category('17') && !is_front_page()) { ?> LOL. It works perfectly now. Thanks guys! Link to comment Share on other sites More sharing options...
Synook Posted May 17, 2010 Share Posted May 17, 2010 You can actually just write and, or, etc. - in PHP they are synonyms with the symbolic representations. Link to comment Share on other sites More sharing options...
risingtalenttv Posted May 17, 2010 Author Share Posted May 17, 2010 You can actually just write and, or, etc. - in PHP they are synonyms with the symbolic representations.Ooh PHP is just the s#it isnt it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.