跳到主要内容
[Navbar 包装器占位符]
[DocBreadcrumbs 包装器占位符 - 面包屑上方]

侧边栏

一、第一种

//侧边栏文章列表,小工具的定义、注册和加载
class Recent_Category_Posts_Widget extends WP_Widget {

public function __construct() {
parent::__construct(
'recent_category_posts_widget',
'最近分类文章小工具',
array('description' => '显示当前分类的最近文章列表,并高亮当前文章')
);
}

public function widget($args, $instance) {
echo $args['before_widget'];

$categories = get_the_category();
$category_name = !empty($categories) ? esc_html($categories[0]->name . " 验厂") : '';

?>
<div class="recent-category-posts">
<div class="widget-title">
<i class="fa fa-list" aria-hidden="true"></i>
<span><?php echo $category_name; ?></span>
</div>
<ul class="post-list">
<?php
$current_post_id = get_the_ID();
if (!empty($categories)) {
$current_category_id = $categories[0]->term_id;

$recent_posts = get_posts(array(
'numberposts' => 20,
'post_status' => 'publish',
'category' => $current_category_id
));

foreach ($recent_posts as $post) :
$post_title = $post->post_title;
$post_url = get_permalink($post->ID);
$is_current = ($post->ID == $current_post_id) ? 'current-post' : '';
?>
<li class="<?php echo $is_current; ?>">
<a href="<?php echo esc_url($post_url); ?>" title="<?php echo esc_attr($post_title); ?>">
<?php echo esc_html($post_title); ?>
</a>
</li>
<?php
endforeach;
}
?>
</ul>
</div>
<?php
echo $args['after_widget'];
}

public function form($instance) {
// Widget admin form
}

public function update($new_instance, $old_instance) {
// Save widget options
return $new_instance;
}
}

function register_recent_category_posts_widget() {
register_widget('Recent_Category_Posts_Widget');
}
add_action('widgets_init', 'register_recent_category_posts_widget');

温馨提示:

这是显示在“上一篇/下一篇”分页按钮上方的自定义文字。

[TOC 包装器占位符 - 目录上方]
Mario
Mario
[Footer 包装器占位符 - 位于页脚上方]

这是通过 Docusaurus Wrapping 统一添加的底部文字内容。

ddddddd