Css 无法设置Wordpress wp\u列表\u类别的样式

Css 无法设置Wordpress wp\u列表\u类别的样式,css,wordpress,wp-list-categories,Css,Wordpress,Wp List Categories,我无法用样式显示我的wp\u列表\u类别。我已经在使用args等,但这似乎无助于解决问题 我想为一篇文章显示相同的子类别 这是我的代码: <?php if (is_home()) { wp_list_categories('orderby=id&title_li=none&depth=1'); } else { $category = get_the_category(); $cat_term_id = $category[0]->term_i

我无法用样式显示我的
wp\u列表\u类别。我已经在使用args等,但这似乎无助于解决问题

我想为一篇文章显示相同的子类别

这是我的代码:

<?php
if (is_home()) {
    wp_list_categories('orderby=id&title_li=none&depth=1');
} else {
    $category = get_the_category();
    $cat_term_id = $category[0]->term_id;
    $cat_category_parent = $category[0]->category_parent;
    $listcat = wp_list_categories('echo=0&child_of='.$cat_category_parent.'&title_li=');
    $listcat = str_replace("cat-item-".$cat_term_id, "cat-item-".$cat_term_id." current-cat", $listcat);
  if ( in_category( $cat_term_id ) || post_is_in_descendant_category( $cat_term_id )) {
      echo $listcat;
  }
}
?>
</ul>


结果如下:

我希望结果如下:


我认为这可能适合您,但我不确定您上面引用的是哪个主题文件

<?php $parent_cat_id = 1; // Change this ID to match the ID value of the "Sepeda" category ?>
<?php $categories = get_categories( "child_of=$parent_cat_id" ); ?> 

<?php if ($categories) : ?>
    <ul id="category-list">
        <?php // Print the link for 'Sepeda' ?>
        <?php echo "<li class='category-name'><a href='" . get_category_link($parent_cat_id) . "'>" . get_cat_name($parent_cat_id) . "</a></li>"; ?>

        <?php // Loop through the sub-categories of 'Sepeda' and print the names and links ?>
        <?php foreach ($categories as $cat) { 
            echo "<li class='category-name'><a href='" . get_category_link( $cat->term_id ) . "'>" . $cat->name . "</a></li>";
        } ?>

        <?php wp_reset_query();  // Restore global post data  ?> 
    </ul>
<?php endif; ?>

谢谢Kory,非常帮助,我感谢你的帮助:)。我只是在第一行代码中添加了主题名称:我更新了我的答案以帮助您。我仍然不能确定我是否完全理解您试图做的事情,但是您应该用上面的新代码替换我第一个答案中的所有旧代码。确保更改第一行上的
$parent\u cat\u id
值,以匹配“Sepeda”类别的id。这个新代码将显示指向“Sepeda”类别及其所有子类别的链接。您可以通过添加
列表样式:无来删除
  • 到CSS的
    #类别列表
    #category-list {
        width: 250px;
        padding: 5px;
        background: white;
        list-style: none;
    }
    .category-name {
        background-color: #694489;
        color: white;
        min-height: 40px;
        text-align: center;
        line-height: normal;
        padding-top: 10px;
    }
    .category-name + .category-name {
        margin-top: 10px;
    }