我还是小孩 發表於 2023-8-31 00:00:00

WordPress打开速度非常慢的解决办法

<p>
<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>今天,特带来了5个实例技巧,至少可以帮助朋友们在减少wordpress博客的负荷上起到一点点作用吧,下面和网友们一起分享一下。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>实例一、在特定的页面加载特定的js和css:在某些特定页面,比如,您在wordpress博客的新建了about us等页面的时候,你可能希望额外加载一些js和css代码,我们只需要在此页面增加即可,不需要在header.php页面增加了,如何做到咧?很简单,将下面的代码复制到您的functions.php文件中即可: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
function extra_assets() { <br>
if(is_page(666)) { // '666' 就是您希望增加css和js的页面id <br>
wp_enqueue_script('my-script', get_template_directory_uri().'/js地址'); <br>
wp_enqueue_style('my-style', get_template_directory_uri().'/css地址'); <br>
} <br>
} <br>
add_action('wp_head','extra_assets'); </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>实例二、增加“查看此分类更多文章”功能:当您在某个分类文章中,想推荐本分类的其余文章的时候,您有可能用到此功能,实现方法很简单,如下: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
function more_from_category($cat_ID) { <br>
if(in_category($cat_ID) { <br>
$posts = get_posts('numberposts=5&amp;category='.$cat_ID); <br>
$output = '&lt;h3&gt;More from this category&lt;/h3&gt;'; <br>
$output.= '&lt;ul&gt;'; <br>
foreach($posts as $post) { <br>
$output.= '&lt;li&gt;&lt;a href="'.get_the_title().'"&gt;'.get_permalink.'&lt;/a&gt;&lt;/li&gt;'; <br>
} <br>
wp_reset_query(); <br>
$output.= '&lt;/ul&gt;'; <br>
echo $output; <br>
} <br>
} </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>将上述代码放入functions.php文件,并在您的single.php文件中使用&gt;&lt;?php more_from_category(666); ?&gt;此代码调用即可,注意咯,666表示你调用的分类id。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>实例三、提醒您自己或您博客作者,他现在位于预览页面上:有的时候,您建立了定时发布,或者您文章发表前需要预览发表效果的时候,您可以能用到此方法: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
function preview_warning() { <br>
if(is_preview()) { <br>
echo '&lt;div id="preview-warning"&gt;Remember, you're still on the Preview page!&lt;div&gt;'; <br>
} <br>
} <br>
add_action('the_content','preview_warning'); </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>当然,这是不够的,你需要编辑style.css的,给予警告文字形状。 </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
#preview-warning { <br>
background:#800; <br>
line-height:50px; <br>
font-size:30px; <br>
font-weight:bold; <br>
text-align:center; <br>
position:fixed; <br>
bottom:0; <br>
} </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>实例四、存档页面仅仅列出文章的标题,而不需要列出文章内容或是摘要:在某些存档页面,比如基于日期的存档页面,我们并不需要列出文章的全部内容或是摘要,只需列出文章标题就足够了,那么is_date()可以帮助你了,只需将下面的代码放入archive.php的循环代码中即可了: </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
if(is_date()) { <br>
//h2可以修改的。. <br>
echo '&lt;h2&gt;'.the_title().'&lt;/h2&gt;'; <br>
} else { <br>
// ... <br>
// else里面的代码就是您archive.php里的循环代码了。 <br>
// ... <br>
} </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>实例五、为你的管理面板增加一个独立的favicon标志:有时候,如果你的firefox浏览器打开了20个页面,你想快速找到自己的博客管理面板,这个时候favicon就帮助你了,另外,此也是个个性的选择哟。在functions.php中增加下面的代码,并制作一个adminfav.ico的ico标志。 </span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
function admin_favicon() { <br>
if(is_admin()) { <br>
echo '&lt;link rel="shortcut icon" href="'.get_bloginfo('url').'/adminfav.ico" /&gt;'; <br>
} <br>
} <br>
add_action('admin_head','admin_favicon'); </p>
頁: [1]
查看完整版本: WordPress打开速度非常慢的解决办法