query_post only works in index (2 posts)

  1. gimperdaniel
    Posted 8 years ago #

    Hi, I am trying to use query_posts from withing a page template...it doesnt work.

    Just for tests I have copied the code from the index page which words and pasted on the template page and it didnt work.. this is what I have in my page template

    <?php query_posts($query_string."&cat=12&showposts=2");?>

    nothing shows up at all. It only works if I remove the $query_string variable, but then the Previous and Next links dont work.

    I have read over and over forum questions and they all say to use the query_post as it is on the top...and i use it on the index page, but it wont work on a template page or a category page

  2. gimperdaniel
    Posted 8 years ago #

    I found out the problem to my own post above and I solved it but it's not in a clean way, I am sure there is a better way to do this...if you know, please let me know.

    The problem was in the $query_string as I figured. Because I am querying a category inside a page If add the query string to the query_posts it will pass the pagename value and that causes it to crash. so I did a str_replace and removed that key and value from the string and left only the paged key and value.

    It works for now

Topic Closed

This topic has been closed to new replies.

About this Topic