您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
6-11: 归档页中调取其下的文章信息
发布时间:2023-03-30 21:45:17编辑:雪饮阅读()
获取文章特色图像,如果没有特色图像就使用默认图像
<?php if(has_post_thumbnail()):?>
<?php the_post_thumbnail('thumbnail');?>
<?php else:?>
<img src="<?php echo get_theme_file_uri();?>/assets/img/default-thumbnail.png" />
<?php endif;?>
获取文章网址、文章标题
<a
href="<?php the_permalink();?>"><?php the_title();?></a>
获取文章摘要,参考5-2: 文章正文自动截取、给嵌套评论添加回复关系信息 (gaojiupan.cn)
<p class="post-des">
<?php if(has_excerpt()):?>
<?php echo get_the_excerpt();?>
<?php else:?>
<?php echo wordpresskt_strim_post_content(120);?>
<?php endif;?>
</p>
获取文章所属分类,这里会获取该文章所有的一大堆所属分类而不是一个分类,暂时先不处理,没有必要纠结,如果只获取一个也有办法就是了。实际上我实际测试下来测试数据里面大多数分类文章是正常的,个别可能为了测试而瞎写的某一个文章就所属于一大堆分类。
<span class="post-meta-it cats">
<?php the_category(",");?>
</span>
获取文章发布时间
<span class="post-meta-it dtime">
<i class="fa fa-clock-o"></i><?php the_time('Y-m-d');?></span>
获取文章浏览次数,参考6-6: 获取文章作者、分类、浏览次数等信息(发布时间,所属分类,浏览次数,作者图像,作者名,作者归档页地址) (gaojiupan.cn)
但这里只做获取不做更新,毕竟是文章列表页
<span class="post-meta-it views">
<i class="fa fa-eye"></i><?php echo wordpresskt_get_postviews(get_the_ID());?></span>
获取文章作者图像、作者链接、作者名称
<a class="avatar"
href="<?php echo get_author_posts_url(get_the_author_meta('ID'));?>">
<?php echo get_avatar(get_the_author_meta('ID'),24);?>
</a>
<a class="nickname"
href="<?php echo get_author_posts_url(get_the_author_meta('ID'));?>">
<?php the_author();?> </a>
获取文章列表数字分页
<div class="posts-nav">
<?php the_posts_pagination();?>
</div>
那么最后归档页代码归总archive.php如
<?php get_header();?>
<div class="container-fluid site-content" id="content">
<div class="row">
<div class="col-md-9 pdfix">
<div class="content-area">
<main class="site-main">
<header class="list-header">
<h1><?php the_archive_title();?></h1>
</header>
<?php if(have_posts()):?>
<?php while(have_posts()):the_post();?>
<article class="postlist-item">
<div class="post-img">
<a
href="<?php the_permalink();?>">
<?php if(has_post_thumbnail()):?>
<?php the_post_thumbnail('thumbnail');?>
<?php else:?>
<img src="<?php echo get_theme_file_uri();?>/assets/img/default-thumbnail.png" />
<?php endif;?>
</a>
</div>
<div class="post-content">
<h2 class="post-title">
<a
href="<?php the_permalink();?>"><?php the_title();?></a>
</h2>
<p class="post-des">
<?php if(has_excerpt()):?>
<?php echo get_the_excerpt();?>
<?php else:?>
<?php echo wordpresskt_strim_post_content(120);?>
<?php endif;?>
</p>
<div class="post-meta">
<div class="post-meta-it author">
<a class="avatar"
href="<?php echo get_author_posts_url(get_the_author_meta('ID'));?>">
<?php echo get_avatar(get_the_author_meta('ID'),24);?>
</a>
<a class="nickname"
href="<?php echo get_author_posts_url(get_the_author_meta('ID'));?>">
<?php the_author();?> </a>
</div>
<span class="post-meta-it dtime">
<i class="fa fa-clock-o"></i><?php the_time('Y-m-d');?></span>
<span class="post-meta-it cats">
<?php the_category(",");?>
</span>
<span class="post-meta-it views">
<i class="fa fa-eye"></i><?php echo wordpresskt_get_postviews(get_the_ID());?></span>
</div>
</div>
</article>
<?php endwhile;?>
<div class="posts-nav">
<?php the_posts_pagination();?>
</div>
<?php else:?>
<?php endif;?>
</main>
</div>
</div>
<?php get_sidebar();?>
</div>
</div>
<?php get_footer();?>
关键字词:归档