I am calling this code from my custom sidebar, in order to get related postings from the same category:
query_posts(array(
'cat' => get_category_id(),
'showposts' => 5,
'post__not_in' => array(get_the_ID())
));
get_template_part('article-list'); // outputs the posts
This works. The have_posts()
-loop inside of my article-list.php now only outputs 5 other postings from the category.
But this also causes a problem: No matter on what kind of page I am (single.php, index.php, ...), WordPress always assumes that I am in the category template. So is_category()
always returns true
after calling query_posts('cat=...')
. Thus is_single()
returns false
, although the single.php-template is used.
What can I do to tell WordPress that it is still using the single-template? Or: What other function can I use to detect which (main) view is loaded?
new WP_Query()
,get_posts()
or one of the filters to alter the statement:pre_get_posts
,posts_clauses
(or similar). In short: There is (close to) no reason to ever usequery_posts()
. For more information about what happens, please refer to the answers at the linked question. Thanks.