WordPress 博客添加文章日历云 – 代码教程
以下是一个简单的代码示例,可以在 WordPress 博客中添加文章日历云。
-
首先,在主题文件夹中创建一个名为 'archive-cloud.php' 的文件。
-
在这个文件中,添加以下代码:
<?php
/**
* Template Name: Archives Cloud
* Description: A custom page template to display archives in a cloud format.
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<div class="page-content">
<h1 class="page-title"><?php the_title(); ?></h1>
<?php
// Get the archives as an array
$archives = wp_get_archives(array(
'type' => 'monthly',
'format' => 'custom',
'before' => '',
'after' => '',
'echo' => 0
));
// Convert the archives to a string
$archives_str = str_replace('</a> (', '</a><span class="count">', $archives);
$archives_str = str_replace(')', '</span>', $archives_str);
// Output the archives in a cloud format
echo '<div class="archives-cloud">' . $archives_str . '</div>';
?>
</div>
</main>
</div>
<?php get_footer(); ?>
-
保存文件并上传到 WordPress 主题文件夹中。
-
在 WordPress 后台,创建一个新页面并选择 'Archives Cloud' 作为页面模板。
-
发布页面并在前台查看效果。
注意:如果您使用的是自定义主题,则可能需要进行一些样式调整,以便使日历云适应您的主题。
原文地址: https://www.cveoy.top/t/topic/nARf 著作权归作者所有。请勿转载和采集!