WordPress different page side bar setting method

Source: Internet
Author: User
Keywords WordPress

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

We in the WordPress theme development process, 8630.html "> Sometimes need to different page design different sidebar, we first look at the implementation of the final effect of the following figure:

  

In the above figure we can see that the homepage and the sidebar of the article page is separate, so we can well control what we want to display.

How can this effect be achieved? The following methods are:

1. Add the following code to the subject's functions.php file:

if (function_exists (' Register_sidebar ')) {Register_sidebar (Array (' name ' => ' Home sidebar ', ' ID ') => ' Widget_homesidebar ', ' before_widget ' => ' <li id= '%1 $ S ' class= ' widget%2 ' > ', ' AFTER_WIDG     Et ' => ' </li> ', ' before_title ' => ' <h2> ', ' after_title ' => ' </h2> ',);         Register_sidebar (Array (' name ' => ' article page sidebar ', ' id ' => ' widget_postsidebar '), ' Before_widget ' => ' <li id= '%1 $ S ' class= ' widget%2 ' > ', ' after_widget ' => ' </li> ', ' Before_title ' =&G T; ' <h2> ', ' after_title ' => ' </h2> ');

}

The above code registers two sidebar: "First page sidebar" and "article page sidebar".

2, in the subject Sidebar file siderbar.php Add the following code:

<?php if (is_home () | | is_front_page ()) {//home page display "First sidebar" if (function_exists (' Dynamic_sidebar ') && D Ynamic_sidebar (' Widget_homesidebar ')) {}}?> <?php if (Is_single ()) {//Article page displays the article page sidebar if (function_exis TS (' Dynamic_sidebar ') && dynamic_sidebar (' Widget_postsidebar ')) {}}?>

OK, look backstage to see the effect!

Reprint Please specify: http://www.54ux.com/a-2328.html

Related Article

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.