WordPress.org

Ready to get started?Download WordPress

Forums

conditionnal tags on sidebar (3 posts)

  1. alysko
    Member
    Posted 5 years ago #

    Hi,

    Into the sidebar (sidebar.php), I show articles I want :
    - A (named) static article
    - last articles
    For that, I use query_posts and the loop.

    Thus, I launch two requests query_posts and two loop (is it better to use get_posts with a foreach ?)
    It works as I wish... but this behavior must be only for the homepage (I use home.php) and problem is here.

    Actually, I wanted to use conditional tags in sidebar but that doesn't work : neither is_home(), nor is_front_page() return correct value (always false while I am on the homepage - root of website -).

    So, why it doesn't work and how can I get it work ?

    Is it stupid to use several loops and is it better to use other type of request (and perhaps directly MySQL request) ?

    Thank you.

  2. alysko
    Member
    Posted 5 years ago #

    Behavior is very strange :

    $wp_query[post][is_home] = false when I choose "Your latest posts" (Settings > Reading)

    $wp_query[post][is_home] = false when I choose "A static page"-"Front page"-(page wanted in home)

    $wp_query[post][is_home] = true when I choose "A static page"-"Posts page" (but doesn't show what I want)

    is_home() seems to be buggy !

  3. melvitax
    Member
    Posted 5 years ago #

    you need to reset the query before the conditional statement
    <?php wp_reset_query(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic