ThemeShaper Forums » Thematic

[closed]

query_posts and is_home issues

(5 posts)
  • Started 3 years ago by darrenc
  • Latest reply from middlesister
  • This topic is not resolved
  1. darrenc
    Member

    on the homepage of my site i want to simply display 3 posts from a certain category. i devised this code, put into my child functions.php:

    add_action("thematic_indexloop", "font_page_loop");
    function font_page_loop(){
    	query_posts('posts_per_page=3&cat=40');
    }
    

    however i noticed that now when i try to do other things on the page using "is_home()" they don't work anymore... almost like the homepage doesn't believe it is a homepage anymore.

    i know that i can workaround this by testing for is_category('40') instead, but my curiosity is getting the better of me:

    - what is actually happening here?
    - is this the best way to be accomplishing what i want?
    -- if not... then what is a better way?

    thanks for any replies.

    Posted 3 years ago #
  2. I prefer making a homepage template then adding the code you can find here:
    http://mygraphicfriend.wordpress.com/2010/01/20/wordpress-create-a-page-template-that-displays-posts-from-a-category-that-has-the-same-name-as-the-page/#comment-133
    (via Pictrix)

    Posted 3 years ago #
  3. darrenc
    Member

    with respect, i don't think that's the most elegant solution. i've done it in 4 lines of code and without creating additional pages to manage. instead of making another homepage template, i could use the childtheme_override_index_loop() in function.php, but i was option for a surgically precise modification since i only need to change 2 things.

    i'm sure there is a way, and i thought query_posts was it... but like i said, i am getting those weird side effects and am curious why.

    Posted 3 years ago #
  4. jmtmay
    Member

    Darrenc, Did you ever figure this out? I'm having the same problem.

    I'm using query_posts, then try to use is_home and it doesn't work. As soon as I take out the query_posts the is_home works.

    Posted 3 years ago #
  5. middlesister
    Member

    This is expected behaviour. Using query_posts will make a new database query, and changing the query will affect global values including changing the conditionals.
    http://codex.wordpress.org/Function_Reference/query_posts

    You might get lucky if you put in a "wp_reset_query()" immediately after the loop.

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.