$cat_id, // 分类ID
'posts_per_page' => 1, // 每页显示的文章数量
'orderby' => 'date', // 按日期排序
'order' => 'ASC', // 升序
);
$cur_post = get_posts($args);
if ($cur_post) {
$content = $cur_post[0]->post_content; // 文章内容
echo $content;
} else {
echo '文章不存在';
}
// 释放查询结果
wp_reset_postdata();
}
// 假设你已经在WordPress环境中,并且有分类ID $category_id
$category_id = $cat_id; // 替换为你的分类ID
// 获取分页参数
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// 查询参数
$args = array(
'cat' => $category_id, // 分类ID
'posts_per_page' => 9, // 每页显示的文章数量
'paged' => $paged
);
// 查询文章
$query = new WP_Query($args);
if ($query->have_posts()) {
echo '
';
while ($query->have_posts()) {
$query->the_post();
// 在这里编写你的文章列表
$post_id = get_the_ID(); // 获取文章ID
$excerpt = get_the_excerpt(); // 获取摘要
if ( mb_strlen( $excerpt ) > 90 ) { // 如果字数超过200字
$excerpt = mb_substr( $excerpt, 0, 90 ); // 截取前200个字符
$excerpt .= '...'; // 添加省略号
}
// 产品介绍模板
if($cat_id == 27){
?>
-
';
// 分页导航
lingfeng_pagenavi();
} else {
// 没有找到文章的提示
echo '没有找到文章。';
}
// 重置WordPress查询
wp_reset_postdata();
?>