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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.