原创内容,转载请注明出处:https://www.myzhenai.com.cn/post/4495.html
前段时间一直在折腾一个问题,其间也放下一段时间,就是我的博客上有文章归档这一功能,但是主题里的文章归档功能调用的是所有时期的文章,这个显示太长了。
自己就想着看看能不能通过修改源码来减少这一部份的显示。
我使用的是twentyten默认主题,我尝试着在主题里找到 archive.php sidebar.php这几个文件中找wp_get_archives()这个函数并修改,但是发现并没有效果。
<li id="archives" class="widget-container">
<h3 class="widget-title"><?php _e( 'Archives', 'twentyten' ); ?></h3>
<?php wp_get_archives( 'type=monthly' ); ?>
<li id="archives" class="widget-container">
<h3 class="widget-title"><?php _e( 'Archives', 'twentyten' ); ?></h3>
<?php wp_get_archives( 'type=monthly', 'limit=>6' ); ?>
<li id="archives" class="widget-container">
<h3 class="widget-title"><?php _e( 'Archives', 'twentyten' ); ?></h3>
<ul>
<?php wp_get_archives( 'type=monthly' ); ?>
</ul>
</li>
#修改成以下的
<li id="archives" class="widget-container">
<h3 class="widget-title"><?php _e( 'Archives', 'twentyten' ); ?></h3>
<ul>
<?php wp_get_archives( 'type=monthly', 'limit=>6' ); ?>
</ul>
</li>
<li id="archives" class="widget-container">
<h3 class="widget-title"><?php _e( 'Archives', 'twentyten' ); ?></h3>
<ul>
<?php wp_get_archives( 'type=monthly' ); ?>
</ul>
</li>
#修改成以下的
<li id="archives" class="widget-container">
<h3 class="widget-title"><?php _e( 'Archives', 'twentyten' ); ?></h3>
<ul>
<?php wp_get_archives( 'type=monthly', 'limit=>6' ); ?>
</ul>
</li>
主要是修改 php wp_get_archives( ‘type=monthly’, ‘limit=>6’ ); 这个函数里最后一边参数,但是却发现没有任何效果。
网上的方法都是教怎样新建一个页面来进行修改,代码是可以抄,但是我却想着怎么不改变现有主题结构的情况下进行修改,所以也放下了一段时间,从昨天开始又有了新思路。
我在想,会不会是小工具的原因?因为我知道我博客上的link链接模块是使用的小工具,所以我进博客后台看了一看,果然是调用的小工具进行归档。

我在网上一查,发现Wordpress的小工具代码是存放在/wp-includes/widgets这个路径下的,我下载了一个新的WordPress安装包,一切换到这个路径下,果然在路径里看到一个 class-wp-widget-archives.php 文件。
打开这个文件一看,里边全是调用文章归档的类和函数。
* Filters the arguments for the Archives widget.
* @since 4.9.0 Added the `$instance` parameter.
* @param array $args An array of Archives option arguments.
* @param array $instance Array of settings for the current widget.
'show_post_count' => $count,
* Filters the arguments for the Archives widget.
* @since 4.9.0 Added the `$instance` parameter.
* @param array $args An array of Archives option arguments.
* @param array $instance Array of settings for the current widget.
'limit' => 12, // 添加这一行,限制为 12 个月
'show_post_count' => $count,
wp_get_archives(
/**
* Filters the arguments for the Archives widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives option arguments.
* @param array $instance Array of settings for the current widget.
*/
apply_filters(
'widget_archives_args',
array(
'type' => 'monthly',
'show_post_count' => $count,
),
$instance
)
);
?>
#修改成以下的
<?php
wp_get_archives(
/**
* Filters the arguments for the Archives widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives option arguments.
* @param array $instance Array of settings for the current widget.
*/
apply_filters(
'widget_archives_args',
array(
'type' => 'monthly',
'limit' => 12, // 添加这一行,限制为 12 个月
'show_post_count' => $count,
),
$instance
)
);
?>
wp_get_archives(
/**
* Filters the arguments for the Archives widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives option arguments.
* @param array $instance Array of settings for the current widget.
*/
apply_filters(
'widget_archives_args',
array(
'type' => 'monthly',
'show_post_count' => $count,
),
$instance
)
);
?>
#修改成以下的
<?php
wp_get_archives(
/**
* Filters the arguments for the Archives widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives option arguments.
* @param array $instance Array of settings for the current widget.
*/
apply_filters(
'widget_archives_args',
array(
'type' => 'monthly',
'limit' => 12, // 添加这一行,限制为 12 个月
'show_post_count' => $count,
),
$instance
)
);
?>
* Filters the arguments for the Archives widget drop-down.
* @since 4.9.0 Added the `$instance` parameter.
* @param array $args An array of Archives widget drop-down arguments.
* @param array $instance Settings for the current Archives widget instance.
$dropdown_args = apply_filters(
'widget_archives_dropdown_args',
'show_post_count' => $count,
switch ( $dropdown_args['type'] ) {
$label = __( 'Select Year' );
$label = __( 'Select Month' );
$label = __( 'Select Day' );
$label = __( 'Select Week' );
$label = __( 'Select Post' );
<?php
/**
* Filters the arguments for the Archives widget drop-down.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives widget drop-down arguments.
* @param array $instance Settings for the current Archives widget instance.
*/
$dropdown_args = apply_filters(
'widget_archives_dropdown_args',
array(
'type' => 'monthly',
'format' => 'option',
'show_post_count' => $count,
),
$instance
);
switch ( $dropdown_args['type'] ) {
case 'yearly':
$label = __( 'Select Year' );
break;
case 'monthly':
$label = __( 'Select Month' );
break;
case 'daily':
$label = __( 'Select Day' );
break;
case 'weekly':
$label = __( 'Select Week' );
break;
default:
$label = __( 'Select Post' );
break;
}
?>
<?php
/**
* Filters the arguments for the Archives widget drop-down.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives widget drop-down arguments.
* @param array $instance Settings for the current Archives widget instance.
*/
$dropdown_args = apply_filters(
'widget_archives_dropdown_args',
array(
'type' => 'monthly',
'format' => 'option',
'show_post_count' => $count,
),
$instance
);
switch ( $dropdown_args['type'] ) {
case 'yearly':
$label = __( 'Select Year' );
break;
case 'monthly':
$label = __( 'Select Month' );
break;
case 'daily':
$label = __( 'Select Day' );
break;
case 'weekly':
$label = __( 'Select Week' );
break;
default:
$label = __( 'Select Post' );
break;
}
?>
修改成
* Filters the arguments for the Archives widget drop-down.
* @since 4.9.0 Added the `$instance` parameter.
* @param array $args An array of Archives widget drop-down arguments.
* @param array $instance Settings for the current Archives widget instance.
$dropdown_args = apply_filters(
'widget_archives_dropdown_args',
'limit' => 12, // 添加这一行,限制为 12 个月
'show_post_count' => $count,
switch ( $dropdown_args['type'] ) {
$label = __( 'Select Year' );
$label = __( 'Select Month' );
$label = __( 'Select Day' );
$label = __( 'Select Week' );
$label = __( 'Select Post' );
<?php
/**
* Filters the arguments for the Archives widget drop-down.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives widget drop-down arguments.
* @param array $instance Settings for the current Archives widget instance.
*/
$dropdown_args = apply_filters(
'widget_archives_dropdown_args',
array(
'type' => 'monthly',
'limit' => 12, // 添加这一行,限制为 12 个月
'format' => 'option',
'show_post_count' => $count,
),
$instance
);
switch ( $dropdown_args['type'] ) {
case 'yearly':
$label = __( 'Select Year' );
break;
case 'monthly':
$label = __( 'Select Month' );
break;
case 'daily':
$label = __( 'Select Day' );
break;
case 'weekly':
$label = __( 'Select Week' );
break;
default:
$label = __( 'Select Post' );
break;
}
?>
<?php
/**
* Filters the arguments for the Archives widget drop-down.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives widget drop-down arguments.
* @param array $instance Settings for the current Archives widget instance.
*/
$dropdown_args = apply_filters(
'widget_archives_dropdown_args',
array(
'type' => 'monthly',
'limit' => 12, // 添加这一行,限制为 12 个月
'format' => 'option',
'show_post_count' => $count,
),
$instance
);
switch ( $dropdown_args['type'] ) {
case 'yearly':
$label = __( 'Select Year' );
break;
case 'monthly':
$label = __( 'Select Month' );
break;
case 'daily':
$label = __( 'Select Day' );
break;
case 'weekly':
$label = __( 'Select Week' );
break;
default:
$label = __( 'Select Post' );
break;
}
?>
把 ‘show_post_count’ => $count, 这一行上面添加 ‘limit’ => 12, 发现问题解决了。


sicnature ---------------------------------------------------------------------
I P 地 址: 52.14.210.44
区 域 位 置: 美国俄亥俄都柏林
系 统 信 息:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普
| 海南乡情论坛 | JiaYu
Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://myzhenai.com/post/4495.html
没有评论