虽然这个博客已经不怎么更新文章了,但是还是会使用下去!
今天发现了Variant 这个主题觉得很不错就更换了下主题,但是这个主题"年久失修",现在用其起来还是有点问题的。
搜索功能失效程序500错误
打开php错误日志发现: PHP Parse error: syntax error, unexpected 'new' (T_NEW) in /xxx/xxx/xxxx/html/wordpress/wp-content/themes/Variant/search.php on line 31
原因:PHP7.0 之后不兼容的错误
我是的php版本是7,wp版本是5.0;因为这个主题就比较早了所以google了下是语法的错误,修改下search.php 第31行的代码即可
解决:
原代码:
Search Results for: <b>“<?php $allsearch = &new WP_Query("s=$s&showposts=-1");$key = wp_specialchars($s, 1);$count = $allsearch->post_count;echo '<span class="search-terms">' . $key . '</span>';wp_reset_query(); ?>”</b>
修改后代码(修改 &new 为 new 即可):
Search Results for: <b>“<?php $allsearch = new WP_Query("s=$s&showposts=-1");$key = wp_specialchars($s, 1);$count = $allsearch->post_count;echo '<span class="search-terms">' . $key . '</span>';wp_reset_query(); ?>”</b>
没有文章归档这个模板
解决:新建一个文章归档的php模板文件代码如下 参考:WordPress文章归档页面
<?php
/*
Template Name: 文章归档
*/
?>
<?php get_header();?>
<div class="m-header ">
<section id="hero1" class="hero">
<div class="inner">
</div>
</section>
<figure class="top-image" style="background-image: url(
<?php
srand( microtime() * 1000000 );
$num = rand( 1, 5 );
$image_file = stripslashes(get_option('strive_indexsuiji'.$num));
echo $image_file;
?> );"></figure>
<canvas height="550" width="1585" id="wave-canvas"></canvas>
<canvas id="wave-canvas"></canvas>
</div>
<main class="main-content">
<section class="section-body">
<?php while ( have_posts() ) : the_post(); ?>
<?php endwhile; ?>
<div class="fancy-archive">
<?php $args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'ignore_sticky_posts' => 1
);
$the_query = new WP_Query( $args );
$posts_rebuild = array();
while ( $the_query->have_posts() ) : $the_query->the_post();
$post_year = get_the_time('Y');
$post_mon = get_the_time('m');
$posts_rebuild[$post_year][$post_mon][] = '<li><a href="'. get_permalink() .'">'. get_the_title() .'</a> <em> ('. get_comments_number('0', '1', '%') .')</em></li>';
endwhile;
wp_reset_postdata();
foreach ($posts_rebuild as $key => $value) {
$output .= '<h3 class="archive-year">' . $key . '</h3>';
$year = $key;
foreach ($value as $key_m => $value_m) {
$output .= '<h3 class="archive-month">' . $year . ' - ' . $key_m . '</h3><ul class="fancy-ul">';
foreach ($value_m as $key => $value_d) {
$output .= $value_d;
}
$output .= '</ul>';
}
}
echo $output;
?>
</div>
</section>
</main>
<?php get_footer();?>
当然也少不了好看的css样式了,把下面代码添加到你的主题style.css文件里面就可以了
/*========================================================
Archive css by bigfa
========================================================*/
.fancy-archive{position:relative;font-size:14px;color:rgba(0,0,0,.6);left:20%;}
.fancy-archive:before{content:"";width:3px;background-color:rgba(0,0,0,.05);position:absolute;top:0;bottom:0;left:100px}
.archive-year{display:inline-block;background-color:#fafafa;border:1px solid rgba(0,0,0,.05);color:rgba(0,0,0,.44);padding:1px 0;width:120px;margin-left:40px;text-align:center;postion:relative;border-radius:3px;margin-top:30px;margin-bottom:10px;position:relative}
.archive-month{position:relative;font-weight:700;margin-bottom:15px}.archive-month:after,.archive-month:before{content:"";background-color:#fff;height:19px;width:19px;border-radius:100%;position:absolute;left:92px;top:3px}.archive-month:after{height:15px;width:15px;background-color:#eee;left:94px;top:5px}.archive-month:hover:after{background-color:#f2e929}
.fancy-ul{margin-left:100px;margin-bottom:30px}.fancy-ul .date{margin-left:-80px;width:80px;display:inline-block}.fancy-ul li{position:relative;padding-left:15px}.fancy-ul li:after,.fancy-ul li:before{content:"";background-color:#fff;height:13px;width:13px;border-radius:100%;position:absolute;left:-5px;top:7px}.fancy-ul li:after{height:9px;width:9px;background-color:#eee;left:-3px;top:9px}
.fancy-ul li:hover:after{background-color:#f2e929}
.main-content{padding-left:60px;padding-right:60px}
@media (max-width:600px){.main-content{padding-left:15px;padding-right:15px}}
@media (max-width:1000px){.main-content{padding-left:15px;padding-right:15px}.fancy-archive{left:0;}}
效果图:
