Wordpress: Use conditional statement for blog decompression

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

  

WordPress Blog Program is currently one of the most mature blog programs, is also the world's largest number of users of the blog program, and as you blog more and more gadgets, plug-ins more and more, followed by your WordPress blog is running faster and slower, how to reduce the pressure on your blog? Today, radish fish has brought 5 examples of skills, at least to help friends in reducing the load on WordPress blog play a little role in it, below and friends to share.

Example one, in a specific page load specific JS and CSS: In some specific pages, for example, you blog in WordPress new about us and other pages, you may want to load additional JS and CSS code, we just need to add this page, Do not need to increase in the header.php page, how to do? Very simply, copy the following code into your functions.php file:

function Extra_assets () {

if (Is_page (666)) {//' 666 ' is the page ID you want to add CSS and JS

Wp_enqueue_script (' My-script ', Get_template_directory_uri (). /js address ");

Wp_enqueue_style (' My-style ', Get_template_directory_uri (). /CSS address ");

}

}

Add_action (' Wp_head ', ' extra_assets ');

Example two, add the "view this category more articles" feature: When you are in a category article, you want to recommend the remainder of this category, you may use this feature, the implementation method is simple, as follows:

function more_from_category ($cat _id) {

if (In_category ($cat _id) {

$posts = get_posts (' numberposts=5&category= '. $cat _id);

$output = ' <h3>more from this category</h3> ';

$output. = ' <ul> ';

foreach ($posts as $post) {

$output. = ' <li><a href= '. Get_the_title (). " > ' Get_permalink. ' </a></li> ';

}

Wp_reset_query ();

$output. = ' </ul> ';

Echo $output;

}

}

Put the above code in the functions.php file and call it in your single.php file, note that 666 indicates the category ID you called.

Example three, remind yourself or your blogger that he is now on the preview page: Sometimes you set up a scheduled release, or you need to preview the publication before it is published, you can use this method:

function preview_warning () {

if (Is_preview ()) {

Echo ' <div id= "preview-warning" >remember, you\ ' re e.g. on the preview ';

}

}

Add_action (' the_content ', ' preview_warning ');

Of course, it's not enough that you need to edit style.css, giving warning text shapes.

#preview-warning {

Background: #800;

line-height:50px;

font-size:30px;

Font-weight:bold;

Text-align:center;

position:fixed;

bottom:0;

}

Example four, the archive page simply lists the title of the article without having to list the content or summary of the article: in some archived pages, such as the Date based archive page, we don't need to list the entire content or summary of the article, just listing the title of the article is enough, then is_date () can help you Just put the following code in the archive.php Loop code:

if (Is_date ()) {

H2 can be modified.

Echo ' <h2> '. The_title (). </h2> ';

else {

// ...

Else inside the code is your archive.php in the loop code.

// ...

}

Example Five, add an independent Favicon logo for your admin panel: Sometimes, if your Firefox browser opens 20 pages, you want to quickly find your own blog management panel, this time Favicon help you, in addition, this is a personality choice yo. Add the following code to the functions.php and make a Adminfav.ico ico flag.

function Admin_favicon () {

if (Is_admin ()) {

Echo ' <link rel= ' disambiguator icon ' href= '. Get_bloginfo (' url '). ' /adminfav.ico "/>";

}

}

Add_action (' Admin_head ', ' Admin_favicon ');

Well, today, radish fish to share this, if you have more personality instances of sharing, or blog experience, can also share with radish fish, this article by the home network of Radish http://www.luoboju.com original published, reproduced please specify, thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.