函数文档

wp_dashboard_site_activity()

💡 云策文档标注

概述

wp_dashboard_site_activity() 是 WordPress 中用于输出仪表板活动小部件的函数,作为 'dashboard_activity' 的回调函数。它通过调用 wp_dashboard_recent_posts() 和 wp_dashboard_recent_comments() 来显示即将发布、最近发布的文章和评论。

关键要点

  • 函数 wp_dashboard_site_activity() 是 'dashboard_activity' Hook 的回调函数,负责生成仪表板的活动小部件。
  • 使用 wp_dashboard_recent_posts() 两次:一次用于获取最多5篇状态为 'future' 的即将发布文章,另一次用于获取最多5篇状态为 'publish' 的最近发布文章。
  • 调用 wp_dashboard_recent_comments() 来显示最近的评论。
  • 如果没有活动(即无文章或评论),则输出 'No activity yet!' 消息。
  • 函数自 WordPress 3.8.0 版本引入。

代码示例

function wp_dashboard_site_activity() {
	echo '';
	$future_posts = wp_dashboard_recent_posts(
		array(
			'max'    => 5,
			'status' => 'future',
			'order'  => 'ASC',
			'title'  => __( 'Publishing Soon' ),
			'id'     => 'future-posts',
		)
	);
	$recent_posts = wp_dashboard_recent_posts(
		array(
			'max'    => 5,
			'status' => 'publish',
			'order'  => 'DESC',
			'title'  => __( 'Recently Published' ),
			'id'     => 'published-posts',
		)
	);
	$recent_comments = wp_dashboard_recent_comments();
	if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) {
		echo '';
		echo '' . __( 'No activity yet!' ) . '';
		echo '';
	}
	echo '';
}

📄 原文内容

Outputs the Activity widget.

Description

Callback function for ‘dashboard_activity’.

Source

function wp_dashboard_site_activity() {

	echo '<div id="activity-widget">';

	$future_posts = wp_dashboard_recent_posts(
		array(
			'max'    => 5,
			'status' => 'future',
			'order'  => 'ASC',
			'title'  => __( 'Publishing Soon' ),
			'id'     => 'future-posts',
		)
	);
	$recent_posts = wp_dashboard_recent_posts(
		array(
			'max'    => 5,
			'status' => 'publish',
			'order'  => 'DESC',
			'title'  => __( 'Recently Published' ),
			'id'     => 'published-posts',
		)
	);

	$recent_comments = wp_dashboard_recent_comments();

	if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) {
		echo '<div class="no-activity">';
		echo '<p>' . __( 'No activity yet!' ) . '</p>';
		echo '</div>';
	}

	echo '</div>';
}

Changelog

Version Description
3.8.0 Introduced.