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