簡單介紹:
WordPress是一種使用PHP語言開發(fā)的博客平臺涣脚,用戶可以在支持PHP和MySQL數(shù)據(jù)庫的服務(wù)器上架設(shè)屬于自己的網(wǎng)站胰耗。也可以把 WordPress當(dāng)作一個(gè)內(nèi)容管理系統(tǒng)(CMS)來使用。
WordPress是一款個(gè)人博客系統(tǒng)芒涡,并逐步演化成一款內(nèi)容管理系統(tǒng)軟件柴灯,它是使用PHP語言和MySQL數(shù)據(jù)庫開發(fā)的。用戶可以在支持 PHP 和 MySQL數(shù)據(jù)庫的服務(wù)器上使用自己的博客费尽。
WordPress有許多第三方開發(fā)的免費(fèi)模板赠群,安裝方式簡單易用。不過要做一個(gè)自己的模板旱幼,則需要你有一定的專業(yè)知識查描。比如你至少要懂的標(biāo)準(zhǔn)通用標(biāo)記語言下的一個(gè)應(yīng)用HTML代碼、CSS柏卤、PHP等相關(guān)知識冬三。
步驟:
- 下載wordpresscms安裝包https://cn.wordpress.org/(官網(wǎng))
- 將壓縮包解壓到配置環(huán)境中,我本地用的phpstudy配置環(huán)境缘缚,要配置php+mysql+apche環(huán)境勾笆,運(yùn)行/wp-admin/setup-config.php
- 在本地?cái)?shù)據(jù)庫中新建wordpress數(shù)據(jù)庫
-
在網(wǎng)頁上運(yùn)行/wp-admin/setup-config.php之后,點(diǎn)擊按鈕進(jìn)行一步步安裝桥滨,安裝完成之后就進(jìn)入了wordpress的后臺界面窝爪,
后臺界面.png - 可以先在本地編寫好你的靜態(tài)頁面之后弛车,然后用wordpress進(jìn)行套站
-
在/wp-content/themes文件夾下建立自己的主題文件夾,然后進(jìn)入后臺的《外觀》-《主題》界面選擇自己建的主題即可
選定自己的自定義主題.png
1蒲每、如何把靜態(tài)頁面制作成主題
2帅韧、有多個(gè)CSS文件的時(shí)候,用哪個(gè)文件作為style.css
制作一個(gè)最簡單的主題啃勉,只需要兩個(gè)文件忽舟,index.php和style.css(放在當(dāng)前文件夾下面)
第一步,準(zhǔn)備靜態(tài)頁面
第二步淮阐,制作index.php和style.css
第三步叮阅,給style.css添加版權(quán)信息
第四步:把主題上傳到空間中wordpress安裝路徑,wp-content/themes/下面泣特,這里主題的文件夾名字必須是英文
第五步浩姥,在wordpress后臺啟用主題
先給style.css添加版權(quán)信息
/*
Theme Name: 自定義
Theme URI: http://www..com
Description: 自定義
Author: 自定義
Author URI: http://www..com
Version: 1.0
Tags: ***
*/
```
Style.css路徑調(diào)用:<?php bloginfo( 'stylesheet_url' ); ?>
主題文件夾路徑:<?php bloginfo('template_directory'); ?>
- 制作頂部header.php和底部footer.php
需要用到的調(diào)用標(biāo)簽:
<?php get_header();?>
<?php get_footer();?>
<?php get_sidebar();?>
獲取主頁路徑:<?php echo get_option('home'); ?>
Header.php中用到的標(biāo)簽:
<meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
<title><?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' | '; } ?> <?php bloginfo('name'); ?></title>
<?php wp_head(); ?>
自定義的導(dǎo)航調(diào)用方法:(分類欄目中的項(xiàng)目)
<?php
$args=array(
'orderby' => 'id',
'order' => 'ASC'
);
$categories=get_categories($args);
foreach($categories as $category) {
echo '<li class="thisclass"><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></li>';
}
?>
- 調(diào)用分類目錄下的內(nèi)容(array數(shù)組里面的數(shù)字就是對應(yīng)的分類欄目的id)
<?php $display_categories = array(1,3,4,130,6,7,8,5);
foreach ($display_categories as $category) { ?>
<div class="P_category">
<?php query_posts("showposts=8&cat=$category")?>
<h2 class="P_c_one"><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></h2>
<ul class="p_news">
<?php while (have_posts()) : the_post(); ?>
<li>· <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo mb_strimwidth(get_the_title(), 0, 40, '…'); ?>
</a> </li>
<?php endwhile; ?>
</ul>
</div>
<?php } wp_reset_query();?>
- 每個(gè)分類欄目對應(yīng)的頁面是category.php,每個(gè)內(nèi)容詳情頁對應(yīng)的頁面是single.php
- 在主題目錄下新建functions.php状您,在里面寫入以下方法勒叠,在后臺《外觀》菜單下面就會出現(xiàn)《菜單》選項(xiàng),在后臺就可以進(jìn)行自定義菜單操作了
if (function_exists('register_nav_menus')) { register_nav_menus(array( 'primary' => '導(dǎo)航菜單', ));
}
在header定義菜單的部分加上即可
<?php
if (function_exists('wp_nav_menu')) {
wp_nav_menu(array(
'theme_location' => 'primary',
'menu_id' => 'nav',
'container' => 'ul',
));
}
?>
![菜單編輯界面.png](http://upload-images.jianshu.io/upload_images/3810529-938b306e596f3620.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 經(jīng)過以上步驟基本就能搭建一個(gè)簡單的cms頁面了膏孟,更多的可以到https://www.wpdaxue.com/進(jìn)行學(xué)習(xí)