• Resolved Stef

    (@inpixelitrust)


    Hi everybody !!

    I’m working on WP 3.0.1, using twenty-ten as a base template to create my own.

    First let me explain what I’m trying to do. I created a website (local only for the moment so no url sorry) using static pages. We want “inside” this website a blog to display a list of news (using posts).
    I tried the “blog-in-blog” plugin but got issues for multilinguism (using WPML), so I finaly tried this codex help . I ended up creating my own template called blog_template.php, to get all the posts in category 1 and 11 to display on my “blog” page (5 per page). The template works fine, the problem is with the sidebar.
    For this website, I created 2 sidebars. The first one (that contains a plugin to display a list of child pages) should only display on “normal” pages. The second sidebar, should display on this blogpage (+ archive pages but that part works).

    Now that you get (I hope) what I’m trying to do, the problem :
    I used the is_page_template in the sidebar.php to make conditionnal statement and check weather or not I’m on the blog template like this :

    <?php
    if ( is_page_template('blog_template.php') ) {
    // here comes my blogsidebar with archive + category links
    echo "blog template";
    }
    elseif ( (is_category())OR(is_single())OR(is_archive())){
    // here comes my blogsidebar with archive + category links
    echo "archive template";
    }
    else {
    // here comes the "page" sidebar with the list of child pages
    echo "normal page";
    <?php endif;
    }
    ?>

    The two last ones work fine, but not the first one.

    The weird part : in my template (blog_template.php) if I call <?php get_sidebar(); ?> AFTER the query_posts + loop, it won’t work, and my echo test gets me “archive template” . If I call <?php get_sidebar(); ?> BEFORE I call the <?php get_sidebar(); ?>, the is_page_template works and the echo test gets me a “blog template”. It seams that wordpress “forgets” he is on the blog-template after my loop. I just don’t get it. I think I might have made a mistake somewhere but after two days looking on google, wordpresscodex and blogs, I did not find anything.

    Here is my query and loop, maybe I did something wrong here :
    [Code moderated as per the Forum Rules. Please use the pastebin]

    This is the loop used in the twenty-ten theme to get the archives. Since I copied / pasted it, I assume that the mistake I’m making is in the query itself ?

    For the moment I’ve two solutions :
    – I can let the <?php get_sidebar(); ?> in blog-template after the loop, and the sidebar will display the same as for archives. Works fine, but not great for further changes (and I have to admit I don’t understand why this works)
    – I can remove <?php get_sidebar(); ?> from the blog-template, and put the hardcore code of my sidebar instead. Here again, not great for flexibility, if I change my mind later, I will have to maintain two files (sidebar + blog-template) instead of just one.

    I’m not quite happy with both solutions, but most of all, I really want to understand what went wrong with my sidebar/is_page_template() to avoid further mistakes so if anybody has got an explantion it would be great !!

    Thanx a lot 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • If your blog page is your main posts page, it will be using the index.php template file – not any custom template you might have applied.

    the original query string – which probably had the information of the page template – might be distorted through the query in the main part –
    try to add wp_reset_query(); before your conditional code.

    Thread Starter Stef

    (@inpixelitrust)

    @ esmi no my blog page is not my main posts page. The page is called “blog”, it has some information like “hello welcome on the blog blabla” to display (from the page called blog) and then I get the posts in the 1 and 11 category from the query in the template. Given to my echo tests, my blog uses the template properly, until the sidebar ^^

    @ alchymyth Amazing idea, works like a charm, you just solved my 2 days problem in one little piece of code! Just to be sure I understand what I did, when I put the wp_reset_query(); before the conditional code, I basically end my category query is that it ?

    Thanks very much to both of you 🙂

    Just to be sure I understand what I did, when I put the wp_reset_query(); before the conditional code, I basically end my category query is that it ?

    yes, basically, you bring the query back to the original state where it was when the page was called

    Thread Starter Stef

    (@inpixelitrust)

    Ok, very nice little trick. Thanx again 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘is_page_template not working when side bar is after query_posts’ is closed to new replies.