• Resolved harjeet singh

    (@harjeet-singh)


    Plz help me out in this

    <?php $cat_include = array($include_category);
    if (in_category($cat_include)) { ?>
    <?php include(TEMPLATEPATH . ‘/new-page.php’); ?> <?php } else { echo ‘nothing’ ; }?>

    Here if value of $include_category is called from database, it doesnt work n passes to else statement. But if i put the value in array after replacing $include_category, it works perfectly.

    I have also checked if the value for $include_category is stored in database by echoing it.

Viewing 15 replies - 1 through 15 (of 15 total)
  • You code looks alright making me think that $include_category isn’t what you think, so add this at the top of your script there:

    echo "<pre>"; print_r($include_category); echo "</pre>";

    Thread Starter harjeet singh

    (@harjeet-singh)

    Thanks for the reply i checked using your code to display the result and the values from database were returned – 5,6

    Thread Starter harjeet singh

    (@harjeet-singh)

    One more thing i have to use the following code also to get the values

    <?php
    global $options;
    foreach ($options as $value) {
    if (get_settings( $value[‘id’] ) === FALSE) { $$value[‘id’] = $value[‘default’]; } else { $$value[‘id’] = get_settings( $value[‘id’] ); } }
    ?>

    Thread Starter harjeet singh

    (@harjeet-singh)

    This is the total code..

    <?php
        global $options;
        foreach ($options as $value) {
        if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['default']; } else { $$value['id'] = get_settings( $value['id'] ); } }
        ?>
        <?php get_header(); ?>
        <div id="container">
        <?php get_sidebar(); ?>
        <div id="content">
        <div class="content-top"></div>
        <div class="content-middle">
        <?php echo "<pre>"; print_r($include_category); echo "</pre>";
        $cat_include = array($include_category);
        if (in_category($cat_include)) { ?>
        <?php include(TEMPLATEPATH . '/new-page.php'); ?>
        <?php } else { echo 'nothing' ; }?>
    
        </div><!-- content_middle closed -->
        <div class="content-bottom"></div>
        <?php if ( comments_open() ) : ?>
        <div id="comments_wrap">
        <?php comments_template(); // Get wp-comments.php template ?>
        </div>
        <?php endif; ?>
        </div><!-- content closed-->
    
        </div><!-- container closed-->
        <?php get_footer(); ?>

    The results are there when typing

    <?php echo "<pre>"; print_r($include_category); echo "</pre>"; ?>

    Just try

    if (in_category($include_category)) { ?>

    Thread Starter harjeet singh

    (@harjeet-singh)

    tried both with array

    if (in_category(array($include_category))) { ?>

    and without array

    if (in_category($include_category)) { ?>

    But still it passes to else command

    Maybe this:

    in_category should be used in The Loop.

    is_category is useful for archive or category template.

    Thread Starter harjeet singh

    (@harjeet-singh)

    but i tried to enter id of one category in database . then the code works fine and includes the new page. the id’s are separated with ‘,’i.e 5,6
    This works fine with

    query_posts(“showposts=8&cat=$include_category”

    Use is_category

    Thread Starter harjeet singh

    (@harjeet-singh)

    is_category doesn’t display anything…..

    Thread Starter harjeet singh

    (@harjeet-singh)

    the only problem is

    retrieving value from database for in_category(array)

    . There must be a way to sort it out.

    Not understanding your problem so will add this as an example for you to consider:

    <?php
    //If in a category archive, get the 'queried category' and display category name/description
    if ( is_category() ) {
    $cat = get_query_var('cat');
    $category=get_category($cat);
    echo '<p>Category Title/Name: '. $category->name . '</p>';  //single_cat_title() will also work for this
    echo '<p>Category Description: '. $category->description . '</p>';
    }
    ?>

    Maybe someone else can see the problem…

    Thread Starter harjeet singh

    (@harjeet-singh)

    My Problem is that i want to retrieve values of category id from database for in_category(array). the following works fine.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php $cat = array(5,6);
    if ( in_category($cat) ) { ?>
    its working
    <?php } else { ?>
    its not working
    <?php } ?>
    <?php endwhile; endif; ?>

    I just want to replace

    <?php $cat = array(5,6);

    with the variable holding value from database

    <?php $cat = array($include_cat);

    Hope this clears everything

    Okay I put a record in wp_options table with the option_value of 5,6

    $cats_to_include = explode(',',get_option('cats_to_include'));
    if ( is_category($cats_to_include) ) {
    echo 'this is category 5 or 6';
    }
    Thread Starter harjeet singh

    (@harjeet-singh)

    Thanks MichaelH.
    That was a great help.
    You Rock man ….

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘in_category(array) problem…plz help’ is closed to new replies.