mediagigolo Posted April 11, 2009 Share Posted April 11, 2009 This might be a snap, but I'm a n00b when it comes to php. This is the script that I need to modify: <?php $aOptions = OnDemand::initOptions(false); ?> <?php if ( have_posts() ) { the_post(); rewind_posts(); } if ( in_category($aOptions['sideblog-cat']) ) { include(TEMPLATEPATH . '/category-blog.php'); } else { include(TEMPLATEPATH . '/category-video.php'); } ?> It's a script used in my WordPress theme. It currently directs visitors (based on their menu choice) to either the "category-blog.php" file or to the "category-video.php" file. I need the above script to reflect 3 options. The third option would be "category-music.php", so it would be "...blog.php" or "...music.php", else "...video.php". I tried using "elseif", but I didn't have any success. Hopefully someone can help me out based on the info provided. Let me know if you require additional info Quote Link to comment https://forums.phpfreaks.com/topic/153676-1st-ever-script-modification/ Share on other sites More sharing options...
revraz Posted April 12, 2009 Share Posted April 12, 2009 What is the criteria that would choose your third option? Quote Link to comment https://forums.phpfreaks.com/topic/153676-1st-ever-script-modification/#findComment-807724 Share on other sites More sharing options...
mediagigolo Posted April 12, 2009 Author Share Posted April 12, 2009 What is the criteria that would choose your third option? The visitor would select "Music" from the pulldown menu. Currently there are 6 choices: Blog, Featured, Movies, Books, Music & Video. Selecting "Blog" from the menu uses the "category-blog.php", while all other selections uses the "category-video.php" file. I want the menu to use "category-music.php" for "music" selections, "category-blog.php" for "blog" selections and "category-video.php" for the remaining 4 selections. Quote Link to comment https://forums.phpfreaks.com/topic/153676-1st-ever-script-modification/#findComment-807738 Share on other sites More sharing options...
Anxious Posted April 12, 2009 Share Posted April 12, 2009 I'm guessing you may be able to use Else If's to be able to add more options, or copy and paste the script below of above, with different includes? not sure if either would cause an error. Maybe this option would work. <?php $aOptions = OnDemand::initOptions(false); ?> <?php if ( have_posts() ) { the_post(); rewind_posts(); } if ( in_category($aOptions['sideblog-cat']) ) { include(TEMPLATEPATH . '/category-blog.php'); } else { include(TEMPLATEPATH . '/category-video.php'); } if ( in_category($aOptions['sideblog-cat']) ) { include(TEMPLATEPATH . '/category-here.php'); } else { include(TEMPLATEPATH . '/category-here.php'); } if ( in_category($aOptions['sideblog-cat']) ) { include(TEMPLATEPATH . '/category-here.php'); } else { include(TEMPLATEPATH . '/category-here.php'); } ?> I'm not sure, as I'm unable to test it, there is another way that I thought of with else if's <?php $aOptions = OnDemand::initOptions(false); ?> <?php if ( have_posts() ) { the_post(); rewind_posts(); } if ( in_category($aOptions['sideblog-cat']) ) { include(TEMPLATEPATH . '/category-blog.php'); } elseif {( in_category($aOptions['sideblog-cat']) ) { include(TEMPLATEPATH . '/category-here.php'); } } elseif {( in_category($aOptions['sideblog-cat']) ) { include(TEMPLATEPATH . '/category-here.php'); } } and so on. Maybe there are better options people could choose. The above may work. They may not. Hope it helps anyway. Quote Link to comment https://forums.phpfreaks.com/topic/153676-1st-ever-script-modification/#findComment-807759 Share on other sites More sharing options...
mediagigolo Posted April 13, 2009 Author Share Posted April 13, 2009 Thanks for taking the time to try to help me out. Between your example and a bit of tweakin' I managed to figure it out: <?php $aOptions = OnDemand::initOptions(false); ?> <?php if ( have_posts() ) { the_post(); rewind_posts(); } if ( in_category($aOptions['sideblog-cat']) ) { include(TEMPLATEPATH . '/category-blog.php'); }else if ( in_category("7") ) { include(TEMPLATEPATH . '/category-music.php'); }else{ include(TEMPLATEPATH . '/category-video.php'); } ?> The reason it wasn't working is that I needed to identify the category id# for music which was "7" Quote Link to comment https://forums.phpfreaks.com/topic/153676-1st-ever-script-modification/#findComment-808351 Share on other sites More sharing options...
Anxious Posted April 19, 2009 Share Posted April 19, 2009 Glad you got it working, can you please mark the topic as solved. Quote Link to comment https://forums.phpfreaks.com/topic/153676-1st-ever-script-modification/#findComment-813738 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.