怎么做網站后臺,網站后端怎么開發
網站后臺又稱網站后端,它是用來控制網站的管理系統。對于制作網站后臺,我們常用的方法就是通過安裝網站程序來生成網站后臺。然后在基本后臺的基礎上進行后臺開發。
學做網站論壇的建站培訓課程中也有專門講解網站后臺開發制作的方法。下面是我們常用的網站后臺開發的操作。
第1節:后臺菜單的注冊、調用
1-1、 在函數文件functions.php文件中添加以下代碼;
//添加菜單功能
if (function_exists('add_theme_support')) {
add_theme_support('nav-menus');
register_nav_menus( array( 'primary' => __( 'Primary Navigation', 'primary' ) ) );
}
1-2、 調用添加的菜單;
<?php wp_nav_menu( array( 'container' => '','menu_class' => 'navigation','menu_id' => "nav_sgBhgn",'depth' => 2, ) ); ?>
第2節:后臺多菜單功能的注冊、調用和使用
1、在函數文件functions.php文件中添加以下代碼;
//添加多個菜單功能
if ( function_exists('register_nav_menus')) {register_nav_menus(array('topmenu' => ' 頂部菜單'));}
if ( function_exists('register_nav_menus')) {register_nav_menus(array('footmenu' =>'底部菜單'));}
2、分別調用代碼:
<?php wp_nav_menu( array( 'theme_location' =>'topmenu','container' => '','menu_class' => 'navigation','menu_id' => "nav_sgBhgn",'depth' => 2, ) ); ?>
添加CSS樣式
#footer li{width:80px;float:left;margin-right:10px}
第3節:后臺小工具的制作和調用
1-1、在functions.php中添加小工具注冊代碼:
//添加小工具功能
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<li>',
'after_widget' => '</li>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
1-2、側邊欄調用小工具;
<!--判斷開始-->
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php endif; ?>
<!--判斷結束-->
第4節:添加自定義小工具模塊
1、制作小工具模塊 熱門文章調用:
<li>
<h2>熱門文章</h2>
<ul>
<?php $popular = new WP_Query('orderby=comment_count&posts_per_page=10'); ?>
<?php while ($popular->have_posts()) : $popular->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
</li>
最新評論調用:
<li>
<h2>最新評論</h2>
<ul>
<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved,comment_author_email, comment_type,comment_author_url, SUBSTRING(comment_content,1,25) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND comment_author != 'admin' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 7";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {
$output .= "\n<li>".strip_tags($comment->comment_author)
."回復說:" ."<a rel='nofollow' href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"" . $comment->post_title . " 上的評論\">". strip_tags($comment->com_excerpt) ."</a></li>";
}
$output .= $post_HTML;
$output = convert_smilies($output);
echo $output;
?>
</ul>
</li>
2、在functions.php文件中注冊小工具模塊:
if( function_exists( 'register_sidebar_widget' ) ) {
register_sidebar_widget('熱門文章模塊','mb_hot');
register_sidebar_widget('最新評論模塊','mb_comments');
}
3、在functions.php文件中調用新添加的小工具模塊
function mb_hot() { include(TEMPLATEPATH . '/remen.php'); }
function mb_comments() { include(TEMPLATEPATH . '/pinglun.php'); }
第5節:網站后臺添加在線客服
- 1、免費js網站下載特效代碼;
- 2、集成代碼到主題中。
- 3、圖片路徑的補充完整:
<?php bloginfo('template_directory'); ?>/kf/images/