Tạo sidebar cho wordpress | How to create multiple dynamic sidebars

Cập nhật lần cuối 16/03/2017 by trong WordPress vào 13/10/2013 có 1842 Views
Tạo sidebar cho wordpress

Tạo sidebar cho wordpress

Mở file functions.php và thêm vào các thuộc tính

<?php
if ( function_exists('register_sidebar') )
register_sidebar();
?>

Các tham số khác có thể tham khảo ví dụ:

<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' =>'</h4>',
));
?>

Có thể tạo thêm nhiều sidebar ở các vị trí khác nhau mà bạn muốn.

<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'sidebar1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array('name'=>'sidebar2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
?>

Và bây giờ nhiệm vụ tiếp theo sẽ hiển thị các sidebars ta đã đăng ký lên bất kỳ chỗ nào bạn muốn

Hiển thị sidebar Sidebar1

<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar1') ) : ?>
<?php endif; ?>

Hiển thị sidebar Sidebar2

<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar2') ) : ?>
<?php endif;>

Các sidebar khác cũng tương tự như vậy

Chúc các bạn thành công!

5/5 - (1 vote)
  • Bình luận
Sản phẩm nổi bật của Toản
x