0

Lately I'm working on wordpress and I have a design somewhat complicated and can not find a function in wordpress especially to print the categories as follows:

<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>

This code should work on the list of the wordpress post. Taking the forech of 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

4

2 に答える 2

0

以下の機能を使用できます

wp_list_categories()
于 2013-11-01T17:07:13.530 に答える
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>";
于 2013-11-01T19:31:23.540 に答える