Wordpress - Need help populating a menu with the titles of Custom Posts with a specific Category
I'm working with Wordpress 3.1.4 - and trying to dynamically populate a menu with Custom Posts with a specific category as you can see here.
So on the page - I have the main loop - which is listing through all of the toy products. The products are all from a custom post t开发者_高级运维ype labelled 'products' - and each product belongs to a different category - soft toys, games etc.
In the sidebar menu, i have written the following code for each category in order to list products within the given category:
<ul class="acitem">
<?php query_posts(array ('post_type' => 'products''cat=games')); ?>
<?php $games_query = new WP_Query("category_name=games"); ?>
<?php while ($games_query->have_posts()) : $games_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
For some reason no list items are being generated. Is it possible this is a conflict with the main loop on the page?
Any suggestions or pointers appreciated! -
PS - I'm using the following plugins:
- custom post type ui
- WP page-navi
in case this has any bearing.
Please try the following code snippet.
<ul class="acitem">
<?php $games_query = new WP_Query(array('post_type'=>'product','category_name'=>'games','posts_per_page'=>-1)); ?>
<?php while ($games_query->have_posts()) : $games_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
http://codex.wordpress.org/Class_Reference/WP_Query
I eventually got this to work by swapping the second line of boxofts' code for the following -
<?php $games_query = new WP_Query('post_type=products&category_name=soft-toys'); ?>
精彩评论