vincentrich
Member
Posted 3 years ago #
<?php
#RETRIEVE CATEGORY ID
$category_id = get_cat_id(single_cat_title("", false));
#RETRIEVE PAGE
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
#RETRIEVE PRODUCTS
query_posts('cat=$category_id&paged=$page&posts_per_page=10');
#DISPLAY PRODUCTS
while(have_posts())
{
the_post();
?>
<?php
}
?>
This is my code. I found the fix on this forum and added it to my code. However, it still does not work in my blog. I still see similar posts on page 1 and 2.
I am trying to display posts from 1 category only.
vincentrich
Member
Posted 3 years ago #
<?php
#RETRIEVE CATEGORY ID
$category_id = get_cat_id(single_cat_title("", false));
#RETRIEVE PAGE
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
#RETRIEVE PRODUCTS
$products = new WP_Query("cat=$category_id&showposts=10&paged=$page");
#DISPLAY PRODUCTS
while($products->have_posts())
{
$products->the_post();
I found a solution. Use WP_Query instead!
mkormendy
Member
Posted 2 years ago #
You didn't have to use WP_Query.
What you had in your first example was almost perfect.
The problem was that you need to use double quotes instead of single quotes when passing variables to the query_posts() function.
<?php
#RETRIEVE CATEGORY ID
$category_id = get_cat_id(single_cat_title("", false));
#RETRIEVE PAGE
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
#RETRIEVE PRODUCTS
query_posts("cat=$category_id&paged=$page&posts_per_page=10");
#DISPLAY PRODUCTS
while(have_posts()) {
the_post();
?>
<?php
}
?>