Wordpress - 需要帮助使用特定类别的自定义帖子标题填充菜单
我正在使用 Wordpress 3.1.4 - 并尝试使用特定类别的自定义帖子动态填充菜单,如您所见
所以在页面上 - 我有主循环 - 列出了所有玩具产品。这些产品均来自标记为“产品”的自定义帖子类型 - 每个产品属于不同的类别 - 毛绒玩具、游戏等。
在侧边栏菜单中,我为每个类别编写了以下代码,以便列出给定类别:
<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>
由于某种原因,没有生成列表项。这是否可能与页面上的主循环发生冲突?
任何建议或指示表示赞赏! -
PS - 我正在使用以下插件:
- 自定义帖子类型 ui
- WP page-navi
以防这有任何影响。
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 type 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请尝试以下代码片段。
http://codex.wordpress.org/Class_Reference/WP_Query
Please try the following code snippet.
http://codex.wordpress.org/Class_Reference/WP_Query
我最终通过将 boxofts 代码的第二行替换为以下代码来实现此目的 -
I eventually got this to work by swapping the second line of boxofts' code for the following -