我之前开发了插件,我是自己写的一个仪表盘小部件吧,用于调用我网站的一些最新文章。效果如下图:
<?php
//添加小工具
function kekcpost(){
$datas = http_get("https://www.kekc.cn/wp-json/wp/v2/posts");
$datajson = json_decode($datas);
echo '<style type="text/css">
#dashboard_wpjam .inside{margin:0; padding:0;}
a.kekc-post {border-bottom:1px solid #eee; margin: 0 !important; padding:6px 0; display: block; text-decoration: none; }
a.kekc-post:last-child{border-bottom: 0;}
a.kekc-post p{display: table-row; }
a.kekc-post img{display: table-cell; width:40px; height: 40px; margin:4px 12px; }
a.kekc-post span{display: table-cell; height: 40px; vertical-align: middle;}
</style>';
echo '<div class="rss-widget">';
for ($i = 0; $i < count($datajson); $i++) {
echo '<a class="kekc-post" target="_blank" href="'.$datajson[$i]->link.'"><p><span>'.($i+1).'、'.$datajson[$i]->title->rendered.'</span></p></a>';
}
echo '</div>';
}
function kekc_post_register_widgets(){
wp_add_dashboard_widget( 'our-css-id', 'KEKC博客最新文章', 'kekcpost');
}
add_action('wp_dashboard_setup', 'kekc_post_register_widgets' );
今天我看到别人也写了一个,效果如下:
都差不多,我是用REST API做的,他是用订阅feed做的,他的代码如下:
//后台仪表盘订阅
function dashboard_custom_feed_output() {
echo '<div class="rss-widget">';
wp_widget_rss_output(array(
'url' => 'http://www.2zzt.com/feed/', //rss地址
'title' => '查看网站的最新内容',
'items' => 6, //显示篇数
'show_summary' => 1, //是否显示摘要,1为显示
'show_author' => 0, //是否显示作者,1为显示
'show_date' => 1 )); //是否显示日期
echo '</div>';
}
function h_add_dashboard_widgets() {
wp_add_dashboard_widget('example_dashboard_widget', '快速了解WP操作', 'dashboard_custom_feed_output');
}
add_action('wp_dashboard_setup', 'h_add_dashboard_widgets' );
声明:本站所有文章,如无特殊说明或标注,均为用户转载互联网发布本平台。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可文章底部留言48小时处理。