I am working on a custom query for a blog category. What I want to do is query posts from an additional category on an existing category page. I am trying to alter the default query to accomplish this. Here is the code I am using.
//add news posts to blog category query
add_action( 'pre_get_posts', 'custom_query_vars' );
function custom_query_vars( $query ) {
if ( is_category( $blog ) && $query->is_main_query() ) {
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query->set( 'post_type', 'any' );
$query->set( 'cat', '228,19' );
$query->set( 'orderby', 'date' );
$query->set( 'posts_per_page', 10 );
$query->set ( 'paged', $paged );
$query->set ( 'order', 'DESC');
}
return $query;
}
The pagination seems to be working fine, and the posts from both categories are being pulled, until I get to around page 70 (where the posts count from the original category would end). From there, pages 71 and on (should go up to page 600 or so accounting for both categories) are all 404 errors. The additional pages do seem to appear in the pagination, they’re just not being generated.
]]>is_category()
without arguments just doesn’t work. I call it at the top of category.php
as the docs say. Since this file is called on any click of a category url, the arguments are in the query. A work around is to call get_query_var('cat')
which returns a string containing the numerical ID of the category or nothing.
]]><?php
if (have_posts()) : while (have_posts()) : the_post();
?>
CONTENT
<?php endwhile; endif; ?>
I want to show for each category only posts that have a specific tag=”big”
so I put right before CONTENT
<?php query_posts( 'tag=big' ); ?>
but suddenly it shows only the last recent post, which also doesn’t have the tag=big
What’s wrong?
]]>I have a parent category page with several child-categories.
When on the parent category page, which runs off a unique template, I’d like to display the latest 5 posts from each of the child categories.
Is there a way to query posts which are children of a category? There seems to be a query for children of posts/pages, but I can’t seem to make the same concept work using categories. The post/page parameter is used in the code I have so far below, although it doesn’t work (‘post_parent’ parameter).
<?php
if ( is_category() ) {
$current_cat = get_query_var('cat');
wp_list_categories('&title_li=&show_count=1&child_of='.$current_cat);
}
?>
<?php
// The Query
query_posts( 'post_parent='.$current_cat );
// The Loop
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
?>
Thanks for any help/suggestions
]]>“Return all posts in any category expetc for posts in category x”
I am sure this is easily acheived
Please let me know
ilan
]]>Here’s the code I’m using:
<ul>
<?php wpsc_start_category_query($category_settings); ?><?php wpsc_start_category_query(array('category_group'=> get_option('wpsc_default_category'), 'show_thumbnails'=> 1)); ?>
<li class='latest_product'>
<a href="<?php wpsc_print_category_url();?>" title='<?php wpsc_print_category_name();?>'>
<?php wpsc_print_category_image(145, 105); ?></a>
<div class="product_info">
<a href="<?php wpsc_print_category_url();?>"><?php wpsc_print_category_name();?></a>
<?php wpsc_print_subcategory("<ul>", "</ul>"); ?>
</div>
</li>
<?php wpsc_end_category_query(); ?>
</ul>
A quick illustration of the output I want would be this:
<"latest_product" li>
<parent category group thumbnail>
<"product_info" div>
<parent category name with link>
<ul, perhaps with a class name so I can style it>
<li>any subcategories for this category</li>
<li>any more subcategories for this category</li>
</ul>
</end "product_info div>
</end "latest_product" li>
Anyone know how I can do this?
]]>My question is, has anyone else encountered this and how do they solve it. Can you suggest another query, written differently to garner the same result that might work?
for example of what works and doesnt work
THIS DOESNT WORK
<select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)" style="width:210px;" align=right>
<option value="#">Browse by Name</option>
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=76&paged=$paged&showposts=200"); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<option value="https://www.sandiegan.com/dining/banquets-catering/#<?php echo $post->ID ?>"><?php echo get_post_meta($post->ID, name, true); ?></option>
<?php endwhile; ?> <?php endif; ?>
</select>
THIS DOES WORK
<select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)" style="width:210px;" align=right>
<option value="#">Browse by Name</option>
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("cat=75&paged=$paged&showposts=200"); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<option value="https://www.sandiegan.com/dining/banquets-catering/#<?php echo $post->ID ?>"><?php echo get_post_meta($post->ID, name, true); ?></option>
<?php endwhile; ?> <?php endif; ?>
</select>
]]><?php
$my_query = new WP_Query(‘category_name=’page_title()-resources’&showposts=3’);
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>