Jump to content

1st Ever Script Modification


mediagigolo

Recommended Posts

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  ;D

Link to comment
https://forums.phpfreaks.com/topic/153676-1st-ever-script-modification/
Share on other sites

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.

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.

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"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.