Support » Fixing WordPress » PHP help.

  • Resolved bryguy73

    (@bryguy73)


    This might be a snap, but I’m a n00b when it comes to php.

    I wanted to post this topic in the advanced section, but you need to be a moderator to do so.

    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 a purchased 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

Viewing 3 replies - 1 through 3 (of 3 total)
  • You probably want something like this:

    if ( in_category($aOptions['sideblog-cat']) ) {
    include(TEMPLATEPATH . '/category-blog.php');
    } elseif ( in_category($aOptions['sidemusic-cat']) ) {
    include(TEMPLATEPATH . '/category-music.php');
    } else {
    include(TEMPLATEPATH . '/category-video.php');
    }

    but that assumes that $aOptions contains a sidemusic-cat

    any help?

    Thanks for the reply. I managed to figure it out just b4 I saw your reply. Here’s what I came up with:

    <?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 important part was identifying the category id# for “music” which was “7”.

    Thanks again

    Hi there

    I am still fairly new to PHP, so I was wondering if someone could tell me how to rewrite the following english into php?

    IF customfield with key “addcontent” value = 1, show posts from category = 1.
    IF customfield with key “addcontent” value = 2, show posts from category = 2.
    etc etc…

    The reasoning is this – i have a static area and a dynamic area on each page, and i would like to be able to pull the latest posts from a certain category and display them only on the page that pertains to them. ie – Static area contains “all about bob”, dynamic area contains “bobs latest posts”.

    This is possible with the blog_in_blog plugin, however i cant seem to make the plugin work with short codes.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP help.’ is closed to new replies.