最简化的版本(一行显示):
php
<?php if ($this->is('category')): ?>

<?php
$currentCatName = $this->getArchiveTitle();
$db = Typecho_Db::get();
$currentCat = $db->fetchRow($db->select('mid')->from('table.metas')
    ->where('name = ?', $currentCatName)->where('type = ?', 'category'));

if ($currentCat):
    $subCategories = $db->fetchAll($db->select()
        ->from('table.metas')
        ->where('parent = ?', $currentCat['mid'])
        ->where('type = ?', 'category'));
    
    if ($subCategories):
?>
    <div class="simple-subcats">
        <span class="label"><?php echo $currentCatName; ?>的子分类:</span>
        <?php foreach ($subCategories as $subCat): ?>
            <a href="<?php echo Typecho_Common::url('category/' . $subCat['slug'], $this->options->index); ?>">
                <?php echo $subCat['name']; ?>(<?php echo $subCat['count']; ?>)
            </a>
        <?php endforeach; ?>
    </div>
<?php endif; endif; ?>

<?php endif; ?>
对应的简洁 CSS:
css
.simple-subcats {

margin: 10px 0 20px;
font-size: 14px;
line-height: 1.6;

}

.simple-subcats .label {

font-weight: bold;
color: #333;

}

.simple-subcats a {

display: inline-block;
margin: 0 10px 0 0;
padding: 2px 8px;
background: #f0f0f0;
border-radius: 3px;
color: #555;
text-decoration: none;

}

.simple-subcats a:hover {

background: #007bff;
color: white;

}

标签: none

添加新评论