[英]Wordpress - Listing of categories not working
I have an interesting one. 我有一个有趣的。 I have a WP site that I need to grab a list of categories for to build a menu from. 我有一个WP网站,我需要获取一个类别列表以从中构建菜单。 I've been looking around and it looks like I'm using the most agreed upon working code, and locally, it works just fine. 我一直在环顾四周,似乎我使用的是最一致认可的工作代码,在本地,它工作得很好。 However, once I upload it to my hosting server (MediaTemple), I find that it is NOT generating the list as I expect. 但是,一旦将其上传到托管服务器(MediaTemple),我发现它没有按预期生成列表。 I have the two sites (locally, MT) set up nearly identical, the only difference is the site on MT has MORE categories. 我将两个站点(在本地为MT)设置几乎相同,唯一的区别是MT上的站点具有更多类别。
Here's what I have: 这是我所拥有的:
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($args);
?>
and then further down: 然后进一步向下:
<ul id="categorySubmenu">
<?php
foreach($categories as $cat) {
?>
<li><?php echo "<a href='" . get_category_link($cat->term_id) . "'> $cat->cat_name </a>" ?></li>
<?php
}
?>
</ul>
In the local site, I'm getting a list in the of all the categories I have in WP (just 2 locally), however, in the hosted site, I get nothing returned there (nothing listed, just an empty <ul></ul>
) 在本地站点中,我获得了WP中所有类别的列表(本地仅2个),但是在托管站点中,我什么也没有返回(没有列出任何内容,只是一个空的<ul></ul>
)
Seems like pretty basic stuff. 似乎很基本的东西。 Is there something I'm missing?!?! 有什么我想念的吗?!?!
Thanks everyone! 感谢大家!
You could change: 您可以更改:
get_category_link($cat->term_id)
To: 至:
get_category_link($cat->cat_ID)
Or you can simply use: 或者您可以简单地使用:
wp_list_categories();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.