2020-02-09 08:52:47 +01:00
< ? php
/**
* SiteMap HTML 版
*/
2020-03-15 14:29:06 +01:00
function gdk_sitemap_html_api_handlers ( $template )
{
2020-02-09 08:52:47 +01:00
2020-03-15 14:29:06 +01:00
$hook = explode ( '-' , get_query_var ( 'sitemap' ));
2020-02-09 08:52:47 +01:00
2020-03-15 14:29:06 +01:00
if ( isset ( $hook [ 0 ]) && $hook [ 0 ] === 'gdkk' ) {
2020-02-09 08:52:47 +01:00
2020-03-15 14:29:06 +01:00
if ( isset ( $hook [ 1 ])) {
2020-02-09 08:52:47 +01:00
status_header ( 404 );
header ( 'HTTP/1.0 404 Not Found' );
$GLOBALS [ 'wp_query' ] -> set_404 ();
2020-03-15 14:29:06 +01:00
include get_query_template ( '404' );
exit ;
2020-02-09 08:52:47 +01:00
}
$sitemap = get_transient ( 'gdk-sitemap-html' );
2020-03-15 14:29:06 +01:00
if ( false === $sitemap || empty ( $sitemap )) {
2020-02-09 08:52:47 +01:00
$sitemap = gdk_create_html_sitemap ();
2020-03-15 14:29:06 +01:00
set_transient ( 'gdk-sitemap-html' , $sitemap );
2020-02-09 08:52:47 +01:00
}
2020-02-11 16:57:47 +01:00
2020-02-09 08:52:47 +01:00
$sitemap ;
return ;
}
2020-03-15 14:29:06 +01:00
return $template ;
2020-02-09 08:52:47 +01:00
}
2020-03-15 14:29:06 +01:00
add_filter ( 'template_include' , 'gdk_sitemap_html_api_handlers' , 99 );
2020-02-11 16:41:23 +01:00
2020-03-15 14:29:06 +01:00
function gdk_create_html_sitemap ()
{
?>
2020-02-09 08:52:47 +01:00
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head profile = " http://gmpg.org/xfn/11 " >
2020-02-11 16:57:47 +01:00
< meta http - equiv = " Content-Type " content = " text/html;charset=UTF-8 " />
2020-03-15 14:29:06 +01:00
< title > 站点地图 -< ? php bloginfo ( 'name' ); ?> </title>
2020-02-09 08:52:47 +01:00
< meta name = " keywords " content = " 站点地图,<?php bloginfo('name'); ?> " />
< meta name = " copyright " content = " <?php bloginfo('name'); ?> " />
< link rel = " canonical " href = " <?php echo get_permalink(); ?> " />
< style type = " text/css " >
2020-02-11 16:57:47 +01:00
body { font - family : Microsoft Yahei , Verdana ; font - size : 13 px ; color : #000;background:#fff;width:990px;margin:0 auto}a:link,a:visited{color:#000;text-decoration:none}a:hover{color:#08d;text-decoration:none}h1,h2,h3,h4,h5,h6{font-weight:400}img{border:0}li{margin-top:8px}.page{padding:4px;border-top:1px solid #eee}.author{background-color:#eef;padding:6px;border-top:1px solid #dde}#content,#footer,#nav{padding:8px;border:1px solid #eee;clear:both;width:95%;margin:auto;margin-top:10px}
2020-02-09 08:52:47 +01:00
</ style >
</ head >
< body vlink = " #333333 " link = " #333333 " >
< h2 style = " text-align: center; margin-top: 20px " >
2020-03-15 14:29:06 +01:00
< ? php bloginfo ( 'name' ); ?> 's SiteMap</h2>
2020-02-09 08:52:47 +01:00
< div id = " nav " >
2020-03-15 14:29:06 +01:00
< a href = " <?php echo esc_url(home_url()); ?>/ " >
< b >< ? php bloginfo ( 'name' ); ?> </b>
2020-02-09 08:52:47 +01:00
</ a >
& raquo ;
< a href = " <?php echo get_permalink(); ?> " > 站点地图 </ a >
</ div >
< div id = " content " >
< h3 > 最新文章 </ h3 >
< ul >
2020-03-15 14:29:06 +01:00
< ? php
$myposts = get_posts ( 'numberposts=-1&orderby=post_date&order=DESC' );
foreach ( $myposts as $post ) : ?>
2020-02-09 08:52:47 +01:00
< li >
< a href = " <?php the_permalink( $post->ID ); ?> " title = " <?php echo $post->post_title ; ?> " target = " _blank " >< ? php echo $post -> post_title ; ?> </a>
</ li >
2020-03-15 14:29:06 +01:00
< ? php endforeach ; ?>
2020-02-09 08:52:47 +01:00
</ ul >
</ div >
< div id = " content " >
< h3 > 分类目录 </ h3 >
2020-03-15 14:29:06 +01:00
< ul >< ? php wp_list_categories ( 'title_li=' ); ?> </ul>
2020-02-09 08:52:47 +01:00
</ div >
< div id = " content " >
< h3 > 单页面 </ h3 >
2020-02-11 16:57:47 +01:00
< ? php wp_page_menu (); ?>
2020-02-09 08:52:47 +01:00
</ div >
< div id = " footer " >
2020-02-11 16:57:47 +01:00
查看网站首页 :
2020-02-09 08:52:47 +01:00
< strong >
2020-03-15 14:29:06 +01:00
< a href = " <?php echo esc_url(home_url()); ?>/ " >< ? php bloginfo ( 'name' ); ?> </a>
2020-02-09 08:52:47 +01:00
</ strong >
</ div >
< br />
< div style = " text-align: center; font-size: 11px " >
Latest Update :
2020-03-15 14:29:06 +01:00
< ? php
global $wpdb ;
$last = $wpdb -> get_results ( " SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private') " );
$last = date ( 'Y-m-d G:i:s' , strtotime ( $last [ 0 ] -> MAX_m ));
echo $last ;
?>
2020-02-09 08:52:47 +01:00
< br />
< br />
</ div >
</ body >
</ html >
< ? php
}
2020-03-15 14:29:06 +01:00
function gdk_clear_sitemap_html_cache ()
{
delete_transient ( 'gdk-sitemap-html' );
2020-02-09 08:52:47 +01:00
}
add_action ( 'publish_post' , 'gdk_clear_sitemap_html_cache' );
add_action ( 'publish_page' , 'gdk_clear_sitemap_html_cache' );
2020-03-15 14:29:06 +01:00
add_action ( 'save_post' , 'gdk_clear_sitemap_html_cache' );