“`php
<div class=”lyz-cat-item-excerpt”>
<?php echo esc_html( lyz_cut_text( … ) ); ?>
</div>
</div> ← 这一行多余,导致 </article> 结构错乱
<a class=”lyz-cat-item-btn” …>查看详情 →</a>
</div>
“`
**修复**:删掉多余的 `</div>`,让 `<a>` 在 `.lyz-cat-item-text` 内部。
下面是**完整修复版 + 分类组合模式**的 `home-sections.php`:
—
## 完整替换 `inc/home-sections.php`
“`php
<?php
if ( ! defined( ‘ABSPATH’ ) ) exit;
/* ============================================================
1. 注册自定义文章类型:首页模块
============================================================ */
function lyz_register_home_sections() {
register_post_type( ‘lyz_section’, array(
‘labels’ => array(
‘name’ => ‘首页模块’,
‘singular_name’ => ‘首页模块’,
‘add_new’ => ‘添加模块’,
‘add_new_item’ => ‘添加新模块’,
‘edit_item’ => ‘编辑模块’,
‘all_items’ => ‘所有模块’,
‘menu_name’ => ‘首页模块’,
),
‘public’ => false,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘menu_position’ => 25,
‘menu_icon’ => ‘dashicons-screenoptions’,
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’, ‘page-attributes’ ),
‘has_archive’ => false,
‘rewrite’ => false,
‘capability_type’ => ‘post’,
) );
}
add_action( ‘init’, ‘lyz_register_home_sections’ );
/* ============================================================
2. 自定义字段 Metabox
============================================================ */
function lyz_section_metabox() {
add_meta_box(
‘lyz_section_meta’,
‘模块设置’,
‘lyz_section_metabox_html’,
‘lyz_section’,
‘normal’,
‘high’
);
}
add_action( ‘add_meta_boxes’, ‘lyz_section_metabox’ );
function lyz_section_metabox_html( $post ) {
wp_nonce_field( ‘lyz_section_save’, ‘lyz_section_nonce’ );
$enable = get_post_meta( $post->ID, ‘_lyz_enable’, true );
$type = get_post_meta( $post->ID, ‘_lyz_type’, true );
$subtitle = get_post_meta( $post->ID, ‘_lyz_subtitle’, true );
$bg_color = get_post_meta( $post->ID, ‘_lyz_bg_color’, true );
$bg_image = get_post_meta( $post->ID, ‘_lyz_bg_image’, true );
$img_pos = get_post_meta( $post->ID, ‘_lyz_img_pos’, true );
$btn1_text = get_post_meta( $post->ID, ‘_lyz_btn1_text’, true );
$btn1_url = get_post_meta( $post->ID, ‘_lyz_btn1_url’, true );
$btn2_text = get_post_meta( $post->ID, ‘_lyz_btn2_text’, true );
$btn2_url = get_post_meta( $post->ID, ‘_lyz_btn2_url’, true );
$cat_id = get_post_meta( $post->ID, ‘_lyz_cat_id’, true );
$cat_count = get_post_meta( $post->ID, ‘_lyz_cat_count’, true );
$left_w = get_post_meta( $post->ID, ‘_lyz_left_width’, true );
$mid_w = get_post_meta( $post->ID, ‘_lyz_mid_width’, true );
if ( $enable === ” ) $enable = ‘1’;
if ( ! $type ) $type = ‘custom’;
if ( ! $img_pos ) $img_pos = ‘right’;
if ( ! $cat_count ) $cat_count = 4;
if ( ! $left_w ) $left_w = ‘33.333333’;
if ( ! $mid_w ) $mid_w = ‘33.333333’;
?>
<table class=”form-table”>
<tr>
<th>启用此模块</th>
<td><label><input type=”checkbox” name=”lyz_enable” value=”1″ <?php checked( $enable, ‘1’ ); ?>> 在首页显示</label></td>
</tr>
<tr>
<th>模块类型</th>
<td>
<select name=”lyz_type”>
<option value=”custom” <?php selected( $type, ‘custom’ ); ?>>自定义内容(手动写)</option>
<option value=”category” <?php selected( $type, ‘category’ ); ?>>分类图文(左图右文交替)</option>
<option value=”portfolio” <?php selected( $type, ‘portfolio’ ); ?>>分类组合(左图卡 + 中列表 + 右小卡)</option>
</select>
</td>
</tr>
<tr>
<th>副标题</th>
<td><input type=”text” class=”large-text” name=”lyz_subtitle” value=”<?php echo esc_attr( $subtitle ); ?>” placeholder=”显示在大标题下方,可留空”></td>
</tr>
<tr>
<th>背景颜色</th>
<td>
<select name=”lyz_bg_color”>
<option value=”auto” <?php selected( $bg_color, ‘auto’ ); ?>>自动(白/灰交替)</option>
<option value=”white” <?php selected( $bg_color, ‘white’ ); ?>>白色</option>
<option value=”gray” <?php selected( $bg_color, ‘gray’ ); ?>>灰色</option>
</select>
</td>
</tr>
<tr>
<th>背景图片</th>
<td><input type=”text” class=”large-text” name=”lyz_bg_image” value=”<?php echo esc_attr( $bg_image ); ?>” placeholder=”留空则使用纯色”></td>
</tr>
</table>
<h3 style=”margin-top:24px;padding-top:16px;border-top:1px solid #eee;”>自定义内容字段</h3>
<table class=”form-table”>
<tr>
<th>图片位置</th>
<td>
<select name=”lyz_img_pos”>
<option value=”right” <?php selected( $img_pos, ‘right’ ); ?>>右图</option>
<option value=”left” <?php selected( $img_pos, ‘left’ ); ?>>左图</option>
<option value=”top” <?php selected( $img_pos, ‘top’ ); ?>>上图</option>
<option value=”none” <?php selected( $img_pos, ‘none’ ); ?>>不显示图片</option>
</select>
<p class=”description”>图片使用右侧栏「特色图片」</p>
</td>
</tr>
<tr><th>按钮 1 文字</th><td><input type=”text” class=”regular-text” name=”lyz_btn1_text” value=”<?php echo esc_attr( $btn1_text ); ?>”></td></tr>
<tr><th>按钮 1 链接</th><td><input type=”url” class=”large-text” name=”lyz_btn1_url” value=”<?php echo esc_attr( $btn1_url ); ?>”></td></tr>
<tr><th>按钮 2 文字</th><td><input type=”text” class=”regular-text” name=”lyz_btn2_text” value=”<?php echo esc_attr( $btn2_text ); ?>”></td></tr>
<tr><th>按钮 2 链接</th><td><input type=”url” class=”large-text” name=”lyz_btn2_url” value=”<?php echo esc_attr( $btn2_url ); ?>”></td></tr>
</table>
<h3 style=”margin-top:24px;padding-top:16px;border-top:1px solid #eee;”>分类字段(类型为「分类图文」或「分类组合」时使用)</h3>
<table class=”form-table”>
<tr>
<th>输入分类 ID</th>
<td>
<input type=”text” class=”regular-text” name=”lyz_cat_id” value=”<?php echo esc_attr( $cat_id ); ?>” placeholder=”例如 3″>
<p class=”description”>多个 ID 用英文逗号 <code>,</code> 隔开</p>
</td>
</tr>
<tr>
<th>显示文章数量</th>
<td><input type=”number” name=”lyz_cat_count” value=”<?php echo esc_attr( $cat_count ); ?>” min=”1″ max=”20″></td>
</tr>
<tr>
<th>左侧宽度(%)</th>
<td><input type=”text” class=”regular-text” name=”lyz_left_width” value=”<?php echo esc_attr( $left_w ); ?>” placeholder=”33.333333″></td>
</tr>
<tr>
<th>中间宽度(%)</th>
<td><input type=”text” class=”regular-text” name=”lyz_mid_width” value=”<?php echo esc_attr( $mid_w ); ?>” placeholder=”33.333333″></td>
</tr>
</table>
<?php
}
/* ============================================================
3. 保存字段
============================================================ */
function lyz_section_save( $post_id ) {
if ( ! isset( $_POST[‘lyz_section_nonce’] ) ) return;
if ( ! wp_verify_nonce( $_POST[‘lyz_section_nonce’], ‘lyz_section_save’ ) ) return;
if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return;
if ( ! current_user_can( ‘edit_post’, $post_id ) ) return;
$texts = array(
‘_lyz_type’ => ‘lyz_type’,
‘_lyz_subtitle’ => ‘lyz_subtitle’,
‘_lyz_bg_color’ => ‘lyz_bg_color’,
‘_lyz_bg_image’ => ‘lyz_bg_image’,
‘_lyz_img_pos’ => ‘lyz_img_pos’,
‘_lyz_btn1_text’ => ‘lyz_btn1_text’,
‘_lyz_btn1_url’ => ‘lyz_btn1_url’,
‘_lyz_btn2_text’ => ‘lyz_btn2_text’,
‘_lyz_btn2_url’ => ‘lyz_btn2_url’,
‘_lyz_cat_id’ => ‘lyz_cat_id’,
‘_lyz_left_width’ => ‘lyz_left_width’,
‘_lyz_mid_width’ => ‘lyz_mid_width’,
);
foreach ( $texts as $meta => $field ) {
if ( isset( $_POST[ $field ] ) ) {
update_post_meta( $post_id, $meta, sanitize_text_field( wp_unslash( $_POST[ $field ] ) ) );
}
}
if ( isset( $_POST[‘lyz_cat_count’] ) ) {
update_post_meta( $post_id, ‘_lyz_cat_count’, intval( $_POST[‘lyz_cat_count’] ) );
}
update_post_meta( $post_id, ‘_lyz_enable’, isset( $_POST[‘lyz_enable’] ) ? ‘1’ : ‘0’ );
}
add_action( ‘save_post’, ‘lyz_section_save’ );
/* ============================================================
4. 后台列表列
============================================================ */
function lyz_section_columns( $columns ) {
$new = array();
foreach ( $columns as $k => $v ) {
$new[ $k ] = $v;
if ( $k === ‘title’ ) {
$new[‘lyz_type’] = ‘类型’;
$new[‘lyz_enable’] = ‘启用’;
$new[‘lyz_order’] = ‘排序’;
}
}
return $new;
}
add_filter( ‘manage_lyz_section_posts_columns’, ‘lyz_section_columns’ );
function lyz_section_column_content( $column, $post_id ) {
if ( $column === ‘lyz_enable’ ) {
$v = get_post_meta( $post_id, ‘_lyz_enable’, true );
echo $v === ‘1’ ? ‘<span style=”color:green;”>● 启用</span>’ : ‘<span style=”color:#999;”>○ 关闭</span>’;
}
if ( $column === ‘lyz_type’ ) {
$t = get_post_meta( $post_id, ‘_lyz_type’, true );
if ( $t === ‘category’ ) echo ‘分类图文’;
elseif ( $t === ‘portfolio’ ) echo ‘分类组合’;
else echo ‘自定义内容’;
}
if ( $column === ‘lyz_order’ ) {
echo get_post_field( ‘menu_order’, $post_id );
}
}
add_action( ‘manage_lyz_section_posts_custom_column’, ‘lyz_section_column_content’, 10, 2 );
/* ============================================================
5. 前台输出
============================================================ */
function lyz_render_home_sections() {
$q = new WP_Query( array(
‘post_type’ => ‘lyz_section’,
‘posts_per_page’ => -1,
‘orderby’ => ‘menu_order’,
‘order’ => ‘ASC’,
‘post_status’ => ‘publish’,
‘no_found_rows’ => true,
) );
if ( ! $q->have_posts() ) return;
while ( $q->have_posts() ) : $q->the_post();
$post_id = get_the_ID();
$enable = get_post_meta( $post_id, ‘_lyz_enable’, true );
if ( $enable !== ‘1’ ) continue;
$type = get_post_meta( $post_id, ‘_lyz_type’, true );
$subtitle = get_post_meta( $post_id, ‘_lyz_subtitle’, true );
$bg_color = get_post_meta( $post_id, ‘_lyz_bg_color’, true );
$bg_image = get_post_meta( $post_id, ‘_lyz_bg_image’, true );
$bg_style = ”;
if ( $bg_image ) {
$bg_style = ‘background-image:url(‘ . esc_url( $bg_image ) . ‘);background-size:cover;background-position:center;’;
} elseif ( $bg_color === ‘gray’ ) {
$bg_style = ‘background:#f8f9fb;’;
} elseif ( $bg_color === ‘white’ ) {
$bg_style = ‘background:#fff;’;
}
$has_bg_image = ! empty( $bg_image );
/* ==================== 分类组合 ==================== */
if ( $type === ‘portfolio’ ) {
$cat_id = get_post_meta( $post_id, ‘_lyz_cat_id’, true );
$left_w = get_post_meta( $post_id, ‘_lyz_left_width’, true );
$mid_w = get_post_meta( $post_id, ‘_lyz_mid_width’, true );
if ( ! $left_w ) $left_w = ‘33.333333’;
if ( ! $mid_w ) $mid_w = ‘33.333333’;
if ( ! $cat_id ) continue;
$cats = array_filter( array_map( ‘intval’, explode( ‘,’, $cat_id ) ) );
$q_left = new WP_Query( array(
‘cat’ => $cats, ‘posts_per_page’ => 4,
‘ignore_sticky_posts’ => true, ‘no_found_rows’ => true, ‘post_status’ => ‘publish’,
) );
$q_mid = new WP_Query( array(
‘cat’ => $cats, ‘posts_per_page’ => 10, ‘offset’ => 4,
‘ignore_sticky_posts’ => true, ‘no_found_rows’ => true, ‘post_status’ => ‘publish’,
) );
$q_right = new WP_Query( array(
‘cat’ => $cats, ‘posts_per_page’ => 3,
‘orderby’ => ‘date’, ‘order’ => ‘ASC’,
‘ignore_sticky_posts’ => true, ‘no_found_rows’ => true, ‘post_status’ => ‘publish’,
) );
if ( ! $q_left->have_posts() && ! $q_mid->have_posts() ) continue;
$right_w = 100 – floatval( $left_w ) – floatval( $mid_w );
if ( $right_w < 10 ) $right_w = 20;
?>
<section class=”lyz-home-section lyz-section-portfolio<?php echo $has_bg_image ? ‘ lyz-section-has-bg’ : ”; ?>” style=”<?php echo esc_attr( $bg_style ); ?>”>
<div class=”lyz-home-section-inner lyz-portfolio-inner”>
<div class=”lyz-portfolio-head”>
<h2 class=”lyz-section-title”><?php the_title(); ?></h2>
<?php if ( $subtitle ) : ?>
<p class=”lyz-section-subtitle”><?php echo esc_html( $subtitle ); ?></p>
<?php endif; ?>
</div>
<div class=”lyz-portfolio-grid”>
<!– 左栏:大图卡片 –>
<div class=”lyz-portfolio-col lyz-portfolio-left” style=”width:<?php echo esc_attr( $left_w ); ?>%;”>
<?php while ( $q_left->have_posts() ) : $q_left->the_post(); ?>
<article class=”lyz-portfolio-card”>
<?php if ( has_post_thumbnail() ) : ?>
<a class=”lyz-portfolio-card-img” href=”<?php the_permalink(); ?>”>
<?php the_post_thumbnail( ‘medium_large’ ); ?>
</a>
<?php endif; ?>
<div class=”lyz-portfolio-card-body”>
<h3 class=”lyz-portfolio-card-title”><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></h3>
<div class=”lyz-portfolio-card-meta”><?php echo esc_html( get_the_date( ‘m/d’ ) ); ?></div>
</div>
</article>
<?php endwhile; wp_reset_postdata(); ?>
</div>
<!– 中栏:编号列表 –>
<div class=”lyz-portfolio-col lyz-portfolio-mid” style=”width:<?php echo esc_attr( $mid_w ); ?>%;”>
<ul class=”lyz-portfolio-list”>
<?php $rank = 0; while ( $q_mid->have_posts() ) : $q_mid->the_post(); $rank++; ?>
<li class=”lyz-portfolio-list-item<?php echo $rank <= 3 ? ‘ is-top’ : ”; ?>”>
<span class=”lyz-portfolio-rank”><?php echo intval( $rank ); ?></span>
<a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a>
</li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>
</div>
<!– 右栏:小卡片 –>
<div class=”lyz-portfolio-col lyz-portfolio-right” style=”width:<?php echo esc_attr( $right_w ); ?>%;”>
<?php while ( $q_right->have_posts() ) : $q_right->the_post(); ?>
<article class=”lyz-portfolio-mini”>
<?php if ( has_post_thumbnail() ) : ?>
<a class=”lyz-portfolio-mini-img” href=”<?php the_permalink(); ?>”>
<?php the_post_thumbnail( ‘medium’ ); ?>
</a>
<?php endif; ?>
<h3 class=”lyz-portfolio-mini-title”><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></h3>
<div class=”lyz-portfolio-mini-meta”><?php echo esc_html( get_the_date( ‘m/d’ ) ); ?></div>
</article>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</div>
</div>
</section>
<?php
continue;
}
/* ==================== 分类图文 ==================== */
if ( $type === ‘category’ ) {
$cat_id = get_post_meta( $post_id, ‘_lyz_cat_id’, true );
$count = (int) get_post_meta( $post_id, ‘_lyz_cat_count’, true );
if ( ! $count ) $count = 4;
if ( ! $cat_id ) continue;
$cats = array_filter( array_map( ‘intval’, explode( ‘,’, $cat_id ) ) );
$q2 = new WP_Query( array(
‘cat’ => $cats,
‘posts_per_page’ => $count,
‘ignore_sticky_posts’ => true,
‘no_found_rows’ => true,
‘post_status’ => ‘publish’,
) );
if ( ! $q2->have_posts() ) { wp_reset_postdata(); continue; }
$i = 0;
?>
<section class=”lyz-home-section lyz-section-cat<?php echo $has_bg_image ? ‘ lyz-section-has-bg’ : ”; ?>” style=”<?php echo esc_attr( $bg_style ); ?>”>
<div class=”lyz-home-section-inner lyz-cat-section-inner”>
<div class=”lyz-cat-section-head”>
<h2 class=”lyz-section-title”><?php the_title(); ?></h2>
<?php if ( $subtitle ) : ?>
<p class=”lyz-section-subtitle”><?php echo esc_html( $subtitle ); ?></p>
<?php endif; ?>
</div>
<div class=”lyz-cat-section-list”>
<?php while ( $q2->have_posts() ) : $q2->the_post();
$i++;
$item_pos = ( $i % 2 === 0 ) ? ‘right’ : ‘left’;
?>
<article class=”lyz-cat-item lyz-cat-item-<?php echo esc_attr( $item_pos ); ?><?php echo has_post_thumbnail() ? ‘ has-thumb’ : ‘ no-thumb’; ?>”>
<?php if ( has_post_thumbnail() ) : ?>
<div class=”lyz-cat-item-image”>
<a href=”<?php the_permalink(); ?>”><?php the_post_thumbnail( ‘large’ ); ?></a>
</div>
<?php endif; ?>
<div class=”lyz-cat-item-text”>
<h3 class=”lyz-cat-item-title”><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></h3>
<div class=”lyz-cat-item-excerpt”>
<?php
$excerpt = get_the_excerpt();
if ( ! $excerpt ) $excerpt = wp_strip_all_tags( get_the_content() );
$excerpt = strip_shortcodes( $excerpt );
$excerpt = preg_replace( ‘/<!–.*?–>/s’, ”, $excerpt );
$excerpt = trim( preg_replace( ‘/\s+/u’, ‘ ‘, $excerpt ) );
echo esc_html( mb_substr( $excerpt, 0, 100, ‘UTF-8’ ) ) . ‘…’;
?>
</div>
<a class=”lyz-cat-item-btn” href=”<?php the_permalink(); ?>”>查看详情 →</a>
</div>
</article>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</div>
</section>
<?php
continue;
}
/* ==================== 自定义内容 ==================== */
$img_pos = get_post_meta( $post_id, ‘_lyz_img_pos’, true );
$btn1_text = get_post_meta( $post_id, ‘_lyz_btn1_text’, true );
$btn1_url = get_post_meta( $post_id, ‘_lyz_btn1_url’, true );
$btn2_text = get_post_meta( $post_id, ‘_lyz_btn2_text’, true );
$btn2_url = get_post_meta( $post_id, ‘_lyz_btn2_url’, true );
$has_thumb = has_post_thumbnail();
?>
<section class=”lyz-home-section lyz-section-img-<?php echo esc_attr( $img_pos ); ?><?php echo $has_bg_image ? ‘ lyz-section-has-bg’ : ”; ?>” style=”<?php echo esc_attr( $bg_style ); ?>”>
<div class=”lyz-home-section-inner”>
<div class=”lyz-section-text”>
<h2 class=”lyz-section-title”><?php the_title(); ?></h2>
<?php if ( $subtitle ) : ?>
<p class=”lyz-section-subtitle”><?php echo esc_html( $subtitle ); ?></p>
<?php endif; ?>
<div class=”lyz-section-content”><?php the_content(); ?></div>
<?php if ( $btn1_text || $btn2_text ) : ?>
<div class=”lyz-section-buttons”>
<?php if ( $btn1_text && $btn1_url ) : ?>
<a class=”lyz-section-btn lyz-btn-primary” href=”<?php echo esc_url( $btn1_url ); ?>”><?php echo esc_html( $btn1_text ); ?></a>
<?php endif; ?>
<?php if ( $btn2_text && $btn2_url ) : ?>
<a class=”lyz-section-btn lyz-btn-outline” href=”<?php echo esc_url( $btn2_url ); ?>”><?php echo esc_html( $btn2_text ); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php if ( $has_thumb && $img_pos !== ‘none’ ) : ?>
<div class=”lyz-section-image”><?php the_post_thumbnail( ‘large’ ); ?></div>
<?php endif; ?>
</div>
</section>
<?php
endwhile;
wp_reset_postdata();
}
“`
—
## `style.css` 末尾追加(只加这一段,前面不动)
“`css
/* ============================================================
分类组合模块(左图卡 + 中列表 + 右小卡)
============================================================ */
.lyz-section-portfolio .lyz-home-section-inner {
display: block !important;
max-width: 1200px;
}
.lyz-portfolio-head {
text-align: center;
max-width: 800px;
margin: 0 auto 40px;
}
.lyz-portfolio-head .lyz-section-title { text-align: center; }
.lyz-portfolio-head .lyz-section-subtitle { text-align: center; }
.lyz-portfolio-grid {
display: flex;
gap: 30px;
align-items: flex-start;
}
.lyz-portfolio-col {
display: flex;
flex-direction: column;
gap: 20px;
min-width: 0;
}
/* 左栏:大图卡 */
.lyz-portfolio-card {
background: #fff;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 4px 16px rgba(0,0,0,.06);
transition: transform .3s, box-shadow .3s;
}
.lyz-portfolio-card:hover {
transform: translateY(-3px);
box-shadow: 0 8px 24px rgba(0,0,0,.1);
}
.lyz-portfolio-card-img {
display: block;
overflow: hidden;
}
.lyz-portfolio-card-img img {
width: 100%;
height: 160px;
object-fit: cover;
display: block;
transition: transform .4s;
}
.lyz-portfolio-card:hover .lyz-portfolio-card-img img {
transform: scale(1.05);
}
.lyz-portfolio-card-body {
padding: 12px 16px 14px;
}
.lyz-portfolio-card-title {
font-size: 15px;
font-weight: 600;
line-height: 1.4;
margin: 0 0 6px;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.lyz-portfolio-card-title a { color: #222; }
.lyz-portfolio-card-title a:hover { color: #2a6df4; }
.lyz-portfolio-card-meta {
font-size: 12px;
color: #999;
}
/* 中栏:编号列表 */
.lyz-portfolio-list {
list-style: none;
margin: 0;
padding: 16px 20px;
background: #fff;
border-radius: 10px;
box-shadow: 0 4px 16px rgba(0,0,0,.06);
}
.lyz-portfolio-list-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 0;
border-bottom: 1px dashed #f0f0f0;
font-size: 14px;
line-height: 1.5;
}
.lyz-portfolio-list-item:last-child { border-bottom: 0; }
.lyz-portfolio-rank {
flex: 0 0 22px;
height: 22px;
line-height: 22px;
text-align: center;
font-size: 12px;
font-weight: 700;
color: #999;
background: #f0f0f0;
border-radius: 4px;
}
.lyz-portfolio-list-item.is-top .lyz-portfolio-rank {
background: #f5222d;
color: #fff;
}
.lyz-portfolio-list-item a {
flex: 1;
min-width: 0;
color: #333;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
.lyz-portfolio-list-item a:hover { color: #2a6df4; }
/* 右栏:小卡片 */
.lyz-portfolio-mini {
background: #fff;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 4px 16px rgba(0,0,0,.06);
transition: transform .3s;
}
.lyz-portfolio-mini:hover { transform: translateY(-3px); }
.lyz-portfolio-mini-img {
display: block;
overflow: hidden;
}
.lyz-portfolio-mini-img img {
width: 100%;
height: 130px;
object-fit: cover;
display: block;
}
.lyz-portfolio-mini-title {
font-size: 14px;
font-weight: 600;
line-height: 1.4;
margin: 10px 14px 4px;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.lyz-portfolio-mini-title a { color: #222; }
.lyz-portfolio-mini-title a:hover { color: #2a6df4; }
.lyz-portfolio-mini-meta {
font-size: 12px;
color: #999;
padding: 0 14px 12px;
}
/* 移动端:三栏变一栏 */
@media (max-width: 768px) {
.lyz-portfolio-head { margin-bottom: 24px; }
.lyz-portfolio-grid {
flex-direction: column;
gap: 20px;
}
.lyz-portfolio-col {
width: 100% !important;
flex: none;
}
.lyz-portfolio-card-img img { height: 180px; }
.lyz-portfolio-mini-img img { height: 160px; }
}
“`
—
## 修复总结
| 问题 | 位置 | 修复 |
|—|—|—|
| 多余的 `</div>` | `home-sections.php` 分类图文模式 | 已删 |
| 摘要用 `wp_trim_words` 对中文失效 | 分类图文 | 改用 `mb_substr` 按字符截取 |
| 无图文章文字只占 55% | 分类图文 CSS | 加 `.no-thumb` / `:has()` 选择器 |
| 缺分类组合模式 | `home-sections.php` | 加上 `portfolio` 分支 |
| 缺分类组合 CSS | `style.css` | 追加 |
—
## 验证
1. 替换 `home-sections.php`
2. `style.css` **末尾追加**分类组合 CSS(**不要**全替换)
3. 宝塔 → PHP-80 → **重载配置**
4. 后台 → **首页模块** → 编辑一个模块:
– **模块类型**选 **”分类组合(左图卡 + 中列表 + 右小卡)”**
– **分类 ID** 填 `3`(或你的分类)
– **左宽** `33.333333`,**中宽** `33.333333`
– **排序** 填个数字
– 保存
5. 前台 `Ctrl + F5` → 截图发我
如果三栏宽度不对,调整 `左宽` + `中宽`(比如 `40` + `30`,右栏自动 30)。