<?php
function moxuan_setup(){
//加载语言文件
load_theme_textdomain('m6',get_template_directory().'/languages');
//注册菜单
register_nav_menus(array(
'primary' => __('Primary Menu','m6'),
'pagemenu' => __('Page Menu','m6')
));
//头部优化
remove_action('wp_head','feed_links',2);
remove_action('wp_head','feed_links_extra',3);
remove_action('wp_head','wp_generator');
remove_action('wp_head','rsd_link');
remove_action('wp_head','wlwmanifest_link');
remove_action('wp_head','wp_generator');
remove_action('wp_head','rel_canonical');
remove_action('wp_head','parent_post_rel_link',10, 0 );
remove_action('wp_head','start_post_rel_link', 10, 0 );
remove_action('wp_head','adjacent_posts_rel_link_wp_head', 10, 0 );
remove_action('wp_head','wp_shortlink_wp_head',10, 0);
//去掉顶部工具条
add_filter('show_admin_bar','__return_false');
//Gzip压缩
//add_action('init','deel_gzip');
//去掉wordpress版本号
add_filter('the_generator','moxuan_remove_version');
//启用特征图片并设置大小
add_theme_support('post-thumbnails');
set_post_thumbnail_size(200,124,true);
//启用友情链接
add_filter('pre_option_link_manager_enabled', '__return_true');
}
add_action('after_setup_theme','moxuan_setup');
/**
* 自定义小工具
*/
function moxuan_widgets_init() {
register_sidebar(array(
'name' => __( 'Primary Sidebar', 'm6' ),
'id' => 'sidebar-1',
'description' => __( 'Main sidebar that appears on the right.', 'm6' ),
'before_widget' => '<div class="sidebar-box %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3><span>',
'after_title' => '</span></h3>',
) );
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_Tag_Cloud');
require get_template_directory() . '/inc/widgets.php';
register_widget('moxuan_widget_comment');
register_widget('moxuan_widget_tag');
}
add_action( 'widgets_init', 'moxuan_widgets_init' );
/**
* 去掉版本号
*/
function moxuan_remove_version() {
return ;
}
/**
* 去掉头部最新评论的内联样式
*/
function moxuan_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action('wp_head',array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'],'recent_comments_style'));
}
add_action('widgets_init','moxuan_remove_recent_comments_style');
/**
* 移除菜单的多余CSS选择器
*/
add_filter('nav_menu_css_class', 'moxuan_css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'moxuan_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'moxuan_css_attributes_filter', 100, 1);
function moxuan_css_attributes_filter($var) {
return is_array($var) ? array_intersect($var, array('current-menu-item','current-post-ancestor','current-menu-ancestor','current-menu-parent','current_page_item')) : '';
}
function moxuan_title() {
if(is_home()){
bloginfo('name');
$paged = get_query_var('paged');
if($paged > 1) printf(' (%s)',$paged);
}
if(is_search()){
wp_title('');
}
if(is_404()){
echo "Page not found";
}
if(is_author()){
}
if(is_single()){
wp_title('');
echo " - ";
bloginfo('name');
}
if(is_category()){
wp_title('');
echo " - ";
bloginfo('name');
$paged = get_query_var('paged');
if($paged > 1) printf(' (%s)',$paged);
}
if(is_page()){
wp_title('');
echo " - ";
bloginfo('name');
}
if(is_month()){
echo "存档";
the_time('YF');
echo " - ";
bloginfo('name');
}
if(is_day()){
}
if(is_tag()){
single_tag_title('',true);
echo " - ";
bloginfo('name');
}
}
/**
* 缩略图获取
*/
function moxuan_get_thumbnail() {
global $post;
if ( has_post_thumbnail() ) {
echo '<a href="'.get_permalink().'">';
the_post_thumbnail();
echo '</a>';
}
else {
//如果文章没有设置缩略图,则查找文章内是否包含图片
$content = $post->post_content;
preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
$n = count($strResult[1]);
if($n > 0){
// 如果文章内包含有图片,就用第一张图片做为缩略图
echo '<a href="'.get_permalink().'"><img src="'.$strResult[1][0].'" /></a>';
}else {
// 如果文章内没有图片,则用默认的图片。
echo '<a href="'.get_permalink().'"><img src="'.get_bloginfo('template_url').'/images/mr.jpg" /></a>';
}
}
}
/**
* 去掉文章默认摘要后的[...]
*/
function moxuan_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more','moxuan_excerpt_more');
/**
* 上一篇,下一篇
*/
if (!function_exists('moxuan_post_nav')) :
function moxuan_post_nav() {
$previous = (is_attachment()) ? get_post(get_post()->post_parent) : get_adjacent_post(false, '', true);
$next = get_adjacent_post(false, '', false);
if (!$next && !$previous) {
return;
}
?>
<div class="post-navigation">
<?php
if ($previous) :
?>
<p><?php _e('Previous Post','m6');previous_post_link('%link','%title'); ?></p>
<?php
endif;
if ($next) :
?>
<p><?php _e('Next Post','m6');next_post_link('%link','%title'); ?></p>
<?php
endif;
?>
</div>
<?php
}
endif;
if(!function_exists('moxuan_comment')):
function moxuan_comment($comment,$args,$depth){
$GLOBALS['comment'] = $comment;
switch ($comment->comment_type) {
case 'pingback':
case 'trackback':
break;
default:
if($commentCounts){
$commentCounts = 1;
}
?>
<div id="div-comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
<div id="comment-<?php comment_ID(); ?>" class="comment-item">
<div class="avatar"><?php echo get_avatar($comment,'50'); ?></div>
<div class="comment-box">
<div class="comment-author"><?php comment_author_link();global $comment_ids;$comment_floor = $comment_ids[get_comment_id()];if ($depth == 1){echo '<span class="floor">'.$comment_floor.'floor</span>';}?></div>
<div class="comment-content"><?php comment_text(); ?></div>
<div class="comment-other"><?php echo get_comment_date('Y/m/d g:i:s');?> <?php comment_reply_link(array_merge( $args, array('depth' => $depth,'max_depth' => $args['max_depth'] ) ) ); ?></div>
</div>
</div>
<?php
break;
}
}
endif;
/**
* 分页
*/
if ( ! function_exists('moxuan_content_pagination' ) ) :
function moxuan_content_pagination() {
if ( is_singular() ) return;
global $wp_query, $paged;
if(!$seed){
$seed = $wp_query->max_num_pages;
}
if ($seed == 1) return;
if($seed > 1){
echo '<div class="pagination">';
if(!$paged){
$paged = 1;
}
$pageNum = 5;
$pv = "";
previous_posts_link(' 上一页 ');
if($seed < 7){
for($i = 1; $i <= $seed; $i++){
if($i == $paged){
$pv .= '<span class="current">'.$i.'</span>';
}
else{
$pv .= "<a href='" . get_pagenum_link($i) ."'>$i</a>";
}
}
}
else{
if($paged <= 3){
$step = 5;
for($i = 1; $i <= $step; $i++){
if($i == $paged){
基于PHP的WordPress主题:M6.zip
版权申诉
155 浏览量
2023-07-23
00:35:08
上传
评论
收藏 158KB ZIP 举报
助力毕业
- 粉丝: 2180
- 资源: 5136
最新资源
- 基于java开发的密码解锁APP,包含手势密码解锁+指纹密码解锁+源码+项目界面展示(毕业设计&课程设计&项目开发)
- 基于单片机的智能窗帘设计
- 基于STM32F103C8T6+LCD1602+MCP6S28的8通道模拟可编程增益放大器Proteus仿真
- 5G RAN NR TDD单用户峰值吞吐率计算过程.pptx
- 基于Objective-C开发的手势密码解锁和面容解锁(代码简洁高效通俗易懂)+源码+开发文档+源码解析(毕业设计&课程设计)
- LangChain学习之 Question And Answer的操作附带数据文件
- linux常用命令大全.zip
- CATIA入门操作案例-正八边异形带孔凸台绘制,等距点绘制正多边形,凸台绘制
- 大型代码语言模型的项目级提示生成pdf
- 纸片战争The War of paper.sb3
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈