安裝源碼
需要服務器有php環境(PHP,Mysql,Apeach/Ngnax)
我用的主機寶(環境一鍵安裝工具)

打開后台突然出現這種情況
Briefly unavailable for scheduled maintenance. Check back in a minute.
這是因為后台在自動更新,需要等待。(一般等待也無用,一直這樣,因為被牆了)
解決辦法:
在網站根目錄,找到.maintenance了,刪除它,就可以了。
Wordpress后台設置
設置->固定鏈接設置


文章列表頁會用到(用於測試,測試完調成正常篇數)
后台插件的刪除與安裝
刪除默認的插件,安裝網站用到的插件(AFC插件(高級自定義字段))
問題1:刪除不了默認插件
刪除不了默認插件,是因為權限問題。
把wp-content目錄的權限設置為“777”,就沒問題了

問題2:添加插件一直打不開,最后超時
修改wp-config.php配置文件,最下邊中添加
set_time_limit(0);
對wordpress的最大執行時間無限制
問題3: 發生意外錯誤,可能WordPress.org或服務器配置文件存在問題。如果該問題持續發生,請考慮去支持論壇尋求幫助
我ping“wordpress.org,cn.wordpress.org”都是250ms,速度太慢了。所以出現這個情況。
創建主題的基礎架構文件
壓縮包在微雲,解壓上傳即可。
網站目錄結構,后台的全局變量頁,自定義分類都有了。
/* Theme Name: Brearing Theme URI: https://www.linqing.cc Author: Roluce Author URI: https://www.linqing.cc Description: this is the first template of roluce. Version: 1.0 License: License License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: Tags This theme, like WordPress, is licensed under the GPL. Use it to make something cool, have fun, and share what you've learned with others. */
<?php /* Template Name: 下載 */ ?>
准備HTML文件
首頁,新聞列表頁,新聞內容頁,產品列表頁,產品內容頁,其他單頁
我用仿站小工具
復制代碼到主題的相關模板頁
上傳img,css,js
替換html(index.php,category.php,single.php)
img/ => <script src="<?php echo get_stylesheet_directory_uri() ?>/img/
css/ => <script src="<?php echo get_stylesheet_directory_uri() ?>/css/
提取header和footer
<?php get_header(); ?>
<?php get_footer(); ?>
<?php get_sidebar(); ?>

內容頁single.php
開頭必須加:
<?php the_post(); ?>
ps:無需循環和query()
導航相關
the_category(',') //在post()下 鏈接+名稱(
$category = get_the_category();
$category[0]->cat_name; //獲取分類名稱
$category[0]->term_id //獲取分類id
get_category_link($category[0]->term_id) //獲取分類的鏈接
get_cat_name( $category[0]->parent); //獲取父類名稱
get_category_link($category[0]->parent); //獲取父類的鏈接
內容相關
the_title( ) //標題 the_content( ) //內容 the_ID() //文章ID the_time('Y/n/j G:i:s') //時間 the_permalink() the_excerpt() //摘要 the_author() <?php echo get_avatar( get_the_author_email(), 36 ); ?> 作者頭像 get_the_title() get_the_author_meta( 'description' )
上一篇/下一篇
<?php if (get_previous_post()) { previous_post_link('上一篇: %link');} else {echo "沒有了,已經是最后文章";} ?> <?php if (get_next_post()) { next_post_link('下一篇: %link');} else {echo "沒有了,已經是最新文章";} ?>
分類頁 category.php
導航相關

$catid = $cat //本分類頁的id <?php echo get_category_link($cat); ?> //本頁分類的鏈接 <?php echo get_cat_name($cat); ?> //本頁分類的名稱(1) single_cat_title(); //本頁分類的名稱(2) single_cat_title( ”, false ); the_category(); //鏈接+名稱(尼瑪格式化的) $cat_obj = get_category($cat); //本頁的父類id $cat_obj->parent, <自定義分類的$cat> $cat_title = single_cat_title('', false); $cats = get_term_by( 'name', $cat_title, 'cat_product' ); $cat= $cats->term_id;
默認文章分類(調用文章列表)
<?php query_posts("showposts=5&cat=21"); //本頁不要這句,自定義分類才用 while( have_posts() ) { the_post(); ?> <tr> <td width="90%" class="fw_t">·<a href="<?php the_permalink(); ?>" target="_blank"><?php the_title();?></a></td> <td width="10%" class="fw_s">[<?php the_time('Y-n-j'); ?>]</td> </tr> <?php } ?> 文章所屬分類和鏈接 $cat = get_the_category( get_the_ID() ); <a href="<?php echo get_category_link($cat[0]->term_id); ?>" class="news_list_cat" target="_blank">[<?php echo $cat[0]->name; ?>]</a>
子分類列表

<?php // 得到所有分類列表 $args=array( 'parent' => '2', 'hide_empty' => 0, //沒文章是否顯示 'orderby'=>'ID', 'number'=>'5' //掉用幾個分類 ); $categories = get_categories($args); foreach ($categories as $cat_item) { ?> <li> <li class="<?php if($cat_item->cat_ID == $cat) echo "thistab"; ?>"> <a href="<?php echo get_category_link($cat_item->cat_ID) ?> "> <?php echo $cat_item->cat_name; ?> </a> <span class="line"></span> </li> </li> <?php } ?>
調用各分類下的文章

<?php //query_posts("showposts=5&cat=$cat"); //無需這句,不然翻頁失效 while( have_posts() ) { the_post(); $cat = get_the_category( get_the_ID() ); //本篇文章的分類數組 ?> <li> <em><?php the_time('Y/n/j'); ?></em> <span></span> <a target="_blank" title="<?php the_title();?>" href="<?php the_permalink(); ?>"> [<?php echo $cat[0]->name; ?>] <?php the_title();?> </a> </li> <?php } ?>
翻頁代碼

重點說明:
1:調用分類下文章時,直接用 while( have_posts() ){…………} 就行。
不必用 query_posts("showposts=5&cat=$cat")
因為在category頁,如果不指定,默認調用本分類{$cat}遍歷文章
2:下邊的翻頁代碼,php代碼部分不用改,只根據頁面調整下css樣式即可(這里是個小難點)
3:每頁顯示多少,由后台的“設置”-->"閱讀設置"控制

<style> /*容器的樣式定義*/ .contain { height: 28px; text-align: center; padding: 20px 0;font-size: 16px;color: #fff;} .screen-reader-text, .pages {display: none;} /*屏蔽標題等(必須的)*/ .contain a { /*A的樣式*/ padding: 5px 12px; margin: 0 2px; border: #a5a5a5 solid 1px; } .pagination span.current, .pagination a:hover{ /*A的選中和懸停的樣式*/ background-color: #a5a5a5; color: #fff; font-weight: 700; padding: 5px 12px; margin: 0 2px; } /*根據網頁情況自己定制的代碼*/ #pages_num{ display:none} #pages_sub{ display:none} </style> <div class="contain"> <?php the_posts_pagination( array( 'prev_text' =>上頁, 'next_text' =>下頁, 'before_page_number' => '<span class="meta-nav screen-reader-text">第 </span>', 'after_page_number' => '<span class="meta-nav screen-reader-text"> 頁</span>', ) ); ?> </div>
列表頁-不同分類id,輸出不同的文本
<?php
$parentid = cate_is_in_descendant_category(2)?2:6; ?> <h2><?php echo $parentid==2?"新聞資訊":"游戲資料";?></h2> <?php // 得到所有分類列表 $args=array( 'parent' => $parentid, 'hide_empty' => 0, //沒文章是否顯示 //'orderby'=>'ID', 'number'=>'6' //掉用幾個分類 ); $categories = get_categories($args); foreach ($categories as $cat_item) { ?> <li> <li class="<?php if($cat_item->cat_ID == $cat) echo "thistab"; ?>"> <a href="<?php echo get_category_link($cat_item->cat_ID) ?> "> <?php echo $cat_item->cat_name; ?> </a> <span class="line"></span> </li> </li> <?php } ?>
內容頁-不同分類id,輸出不同的文本
<?php $parentid = post_is_in_descendant_category(2)?2:6; ?> <h2><?php echo $parentid==2?"新聞資訊":"游戲資料";?></h2>
