WordPress 自定义存档页面-外加自定义类型文章

Mr.Wu 1,808 0 正在检测是否收录...

WordPress 自定义存档页面-外加自定义类型文章

存档页添加如下代码:

<?php
/*
template name:文章存档
description: template for https://www.mrwu.red/ XiaoXiaoWu theme
*/
?>
// 这里添加你的主题页头
<?php
$args = array(
'posts_per_page' => -1,
'post_type' => array( 'post','product','shuoshuo'), //根据你的主题自行修改array中的值,如果只想显示默认类型文章,这行删除 ,'product','shuoshuo'
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
);
$yearpost = new WP_Query( $args );
$i = 1;
?>
<section class="animated bounceInLeft">
<article class="post single">
<?php if($yearpost->have_posts()) : ?>
<?php while($yearpost->have_posts()) : $yearpost->the_post() ?>
<?php if( $date != date( 'Y', strtotime($post->post_date) ) ){ ?>
</ul>
<h2 itemprop="name headline" class="fh"><?php echo date( 'Y', strtotime($post->post_date) ); ?></h2>
<ul style="background: #fff;color: #9E9E9E;">
<?php }else{ ?>
<?php if( $i == 1 ){ ?>
<div><?php echo date( 'Y', strtotime($post->post_date) ); ?></div>
<ul>
<?php } ?>
<?php } ?>
<li id="post-<?php the_ID(); ?>"><time datetime="<?php the_time('Y-m-d h:i:s'); ?>"><?php the_time('Y-m-d'); ?></time> <span>—</span> <a href="<?php%20the_permalink();%20?>" class="gdbt" title="<?php the_title(); ?>">[ <?php the_title(); ?> ] </a></li>
<?php $i++; $ul = 0; $date = date( 'Y', strtotime($post->post_date) ); endwhile; ?>
<?php endif; wp_reset_query(); ?>
</div>
</div>
//这里添加你的主题的页尾

这里我就不提供CSS样式了,因为我的主题样式和你的肯定不同的,你可以参考我的 [ 存档页面 ] F12 根据我的样式修改。

打赏
发表评论 取消回复
表情 图片 链接 代码

分享
微信
微博
QQ