最近我正在研究wordpress,我的设计有点复杂,无法在wordpress中找到功能,特别是按以下方式打印类别:
<ul>
<li><a href="">Category 1</a></li>
<li><a href="">Category 2</a></li>
<li><a href="">Category 3</a></li>
<li><a href="">More Categories</a>
<ul>
<li><a href="">Category 4</a></li>
<li><a href="">Category 5</a></li>
<li><a href="">Category 6</a></li>
<li><a href="">Category 7</a></li>
</ul>
</li>
</ul>
此代码应该在wordpress帖子列表中工作。采取wordpress的预兆
foreach((get_the_category()) as $cat) {
echo '<li><a href="'.get_category_link($cat->cat_ID).'">' . $cat->cat_name . '</a><li>';
}
http://codex.wordpress.org/Function_Reference/get_the_category
答案 0 :(得分:0)
你可以使用以下功能
wp_list_categories()
答案 1 :(得分:0)
你可以这样做:
$hasmore=false;
$i=0;
foreach((get_the_category()) as $cat) {
if($i==3)
{
$hasmore=true;
echo '<li><a href="UnansweredCommentQuestion.php">More Categories</a><ul>';
}
echo '<li><a href="'.get_category_link($cat->cat_ID).'">' . $cat->cat_name . '</a></li>';
$i++;
}
if($hasmore) echo "</ul></li>";