|
復(fù)制代碼 代碼如下:
<?php
/*
在根目錄 -> wp-content -> themes 下創(chuàng)建mytheme文件夾用來(lái)存放創(chuàng)建新主題模板
在mytheme目錄下創(chuàng)建 index.php ,style.css 兩個(gè)文件,在wp后臺(tái) 外觀->主題 中就可以看到剛創(chuàng)建的主題
打開style.css文件輸入
*/
?>
/*
Theme Name: 這里填主題名稱
Theme URI: 這里填主題介紹的網(wǎng)址,沒有就填你的博客網(wǎng)址吧
Description:這里填主題的簡(jiǎn)短介紹
Author: 作者名
Author URI: 作者的網(wǎng)址
Version: 版本號(hào)
Tags: 標(biāo)簽,多個(gè)用半角逗號(hào)隔開
*/
<?php
/*
在后臺(tái)主題管理中即可看到主題相關(guān)信息,css中主題信息內(nèi)容必須用注釋符號(hào)括起來(lái)
找一個(gè)300*225的png圖片,命名為 screenshot.png 放在主題目錄下(mytheme文件夾中),在主題管理頁(yè)中即可看到新建主題的預(yù)覽圖片
//==================================================header================================================================
可以把網(wǎng)站相同頭內(nèi)容放在一個(gè)頭文件中,在主題目錄下新建 header.php 文件向其中輸入輸入 統(tǒng)一的頭部?jī)?nèi)容
在 index.php 或想調(diào)用該header.php頁(yè)面的頁(yè)面中 輸入
*/
get_header(); //get_header()就相當(dāng)于將header.php中的代碼拷貝到當(dāng)前的php文件
/*
在主題管理頁(yè)面,該主題實(shí)時(shí)預(yù)覽中,默認(rèn)打開的 index.php 頁(yè)面中即可引入 header.php 頁(yè)面的內(nèi)容
header.php 將會(huì)被所有的模板頁(yè)面(主頁(yè)、分類頁(yè)、頁(yè)面、標(biāo)簽頁(yè)等)所包含,所以 header.php 中代碼應(yīng)該是動(dòng)態(tài)的。
不同頁(yè)面的title都是不一樣,而且title的設(shè)置還會(huì)直接影響到SEO的效果,所以這里應(yīng)該謹(jǐn)慎設(shè)置。下面提供一種SEO優(yōu)化的title寫法,
在header.php頁(yè)面添加
*/
?>
<title>
<?php
if (is_home ()) { // is_home() 當(dāng)前頁(yè)面為主頁(yè)時(shí)返回true
bloginfo ( 'name' ); // 返回站點(diǎn)標(biāo)題
echo " - ";
bloginfo ( 'description' ); // 返回站點(diǎn)副標(biāo)題,站點(diǎn)描述
} elseif (is_category ()) { // is_category() 當(dāng)前頁(yè)面為分類頁(yè)時(shí)返回true
single_cat_title ();
echo " - ";
bloginfo ( 'name' );
} elseif (is_single () || is_page ()) { // is_single() 當(dāng)前頁(yè)面為單文章頁(yè)時(shí)返回true 。 is_page() 當(dāng)前頁(yè)面為單頁(yè)面時(shí)返回true
single_post_title ();
} elseif (is_search ()) { // is_search() 當(dāng)前頁(yè)面為搜索頁(yè)時(shí)返回true
echo "搜索結(jié)果";
echo " - ";
bloginfo ( 'name' );
} elseif (is_404 ()) { // is_404() 當(dāng)前頁(yè)面為404頁(yè)時(shí)返回true
echo '頁(yè)面未找到!';
} else {
wp_title ( '', true );
}
?>
</title>
<?php
/*
以上添加的php代碼運(yùn)用了條件判斷,針對(duì)不同的頁(yè)面采用不同title
在 header.php 頁(yè)面中添加默認(rèn) style.css 文件
*/
?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<?php
/*
bloginfo('stylesheet_url');返回的是主題默認(rèn)style.css文件絕對(duì)網(wǎng)址路徑,如
http://localhost/wordpress/wp-content/themes/myTheme/style.css
bloginfo('template_url');返回的是主題目錄的絕對(duì)網(wǎng)址路徑,可以用來(lái)模板中連接樣式圖片,如
http://localhost/wordpress/wp-content/themes/mytheme
添加 pingback 通告功能,在header.php頁(yè)面 <head> 標(biāo)簽中里面添加代碼:
*/
?>
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php
/*
添加訂閱feed鏈接,在header.php頁(yè)面 <head> 標(biāo)簽中添加:
*/
?>
<link rel="alternate" type="application/rss+xml" title="RSS 2.0 - 所有文章" href="<?php echo get_bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0 - 所有評(píng)論" href="<?php bloginfo('comments_rss2_url'); ?>" />
<?php
/*
添加wp_head,有些插件需要在網(wǎng)頁(yè)頭部添加一些js或css,要讓這些插件能夠正常的工作,也讓主題有更好的兼容性,應(yīng)該添加wp_head()函數(shù)
header.php 頁(yè)面 <head> 標(biāo)簽中添加
*/
?>
<?php wp_head(); //用于包含WordPress程序輸出頭部信息 ?>
<?php
/*
顯示菜單欄,這里只在菜單欄中列出分類頁(yè)和page頁(yè)面,可以根據(jù)喜好來(lái)列出想要的。header.php中
*/
?>
<ul id="navigation" class="grid_8">
<?php wp_list_categories(); //用于列出博客分類頁(yè) ?>
<?php wp_list_pages('depth=1&title_li=0&sort_column=menu_order'); //用于列出博客頁(yè)面,可不填參數(shù) ?>
</ul>
<?php
//==================================================footer================================================================
/*
footer.php與header.php差不多,寫這個(gè)文件的目的也是為了精簡(jiǎn)代碼,提高代碼的重用性。
在主題目錄中創(chuàng)建 footer.php ,在 index.php 或想調(diào)用該footer.php頁(yè)面的頁(yè)面中使用
*/
get_footer();//功能和get_header()類似
/*
在footer.php頁(yè)面添加 wp_footer提高兼容性
*/
wp_footer();
/*
wp_footer()和wp_head()差不多,都是用于提高主題兼容性,畢竟有很多插件要在頁(yè)腳輸出一些東西才能正常工作。
*/
//==================================================sidebar================================================================
/*
在主題目錄下新建 sidebar.php 頁(yè)面,在 index.php 或想調(diào)用該sidebar.php頁(yè)面的頁(yè)面中添加
*/
get_sidebar();
/*
調(diào)用 sidebar.php 頁(yè)面內(nèi)容
為使WordPress后臺(tái) -> 外觀 -> 小工具,可以正常地拖動(dòng)小工具到側(cè)邊欄
在 sidebar.php 頁(yè)面的列表格式應(yīng)按如下舉例格式
*/
?>
<div>
<?php
if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'First_sidebar' )) ://First_sidebar為widget名稱,要和functions.php中對(duì)應(yīng)的widget name相同
?>
<h4>分類目錄</h4>
<ul>
<?php wp_list_categories('depth=1&title_li=&orderby=id&show_count=0&hide_empty=1&child_of=0'); ?>
</ul>
<?php endif; ?>
<?php
if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'Second_sidebar' )) :
?>
<h4>最新文章</h4>
<ul>
<?php
$posts = get_posts ( 'numberposts=6&orderby=post_date' );
foreach ( $posts as $post ) {
setup_postdata ( $post );
echo '<li><a href="' . get_permalink () . '">' . get_the_title () . '</a></li>';
}
$post = $posts [0];
?>
</ul>
<?php endif; ?>
<?php
if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'Third_sidebar' )) :
?>
<h4>標(biāo)簽云</h4>
<p><?php wp_tag_cloud('smallest=8&largest=22'); ?></p>
<?php endif; ?>
<?php
if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'Fourth_sidebar' )) :
?>
<h4>文章存檔</h4>
<ul>
<?php wp_get_archives('limit=10'); ?>
</ul>
<?php endif; ?>
</div>
<?php
/*
同時(shí)在主題目錄下創(chuàng)建 functions.php 文件內(nèi)容為
*/
/** widgets */
if( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'First_sidebar', //name就是給widget指定各自的名稱,以便在sidebar.php中分別調(diào)用.所以只需要給這兩個(gè)widget取兩個(gè)名字就好了。
'before_widget' => '', //定義Widget內(nèi)容的前后標(biāo)識(shí)符的語(yǔ)句
'after_widget' => '',
'before_title' => '<h4>', //定義Widget標(biāo)題的前后標(biāo)識(shí)符的語(yǔ)句
'after_title' => '</h4>'
));
register_sidebar(array(
'name' => 'Second_sidebar',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
register_sidebar(array(
'name' => 'Third_sidebar',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
register_sidebar(array(
'name' => 'Fourth_sidebar',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
}
/*
這樣WordPress后臺(tái) -> 外觀 -> 小工具,就可以正常地拖動(dòng)小工具到側(cè)邊欄了
制作index.php 文章列表
例子
*/
?>
<div class="grid_8">
<!-- Blog Post -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post">
<!-- Post Title -->
<h3 class="title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<!-- Post Data -->
<p class="sub"><?php the_tags('標(biāo)簽:', ', ', ''); ?> • <?php the_time('Y年n月j日') ?> • <?php comments_popup_link('0 條評(píng)論', '1 條評(píng)論', '% 條評(píng)論', '', '評(píng)論已關(guān)閉'); ?><?php edit_post_link('編輯', ' • ', ''); ?></p>
<div class="hr dotted clearfix"> </div>
<!-- Post Image -->
<img class="thumb" alt="" src="<?php bloginfo('template_url'); ?>/images/610x150.gif" />
<!-- Post Content -->
<?php //the_excerpt(); ?>
<?php the_content('閱讀全文...'); ?>
<!-- Read More Button -->
<p class="clearfix"><a href="<?php the_permalink(); ?>" class="button right">閱讀全文</a></p>
</div>
<div class="hr clearfix"> </div>
<?php endwhile; ?>
<!-- Blog Navigation -->
<p class="clearfix"><?php previous_posts_link('<< 查看新文章', 0); ?> <span class="float right"><?php next_posts_link('查看舊文章 >>', 0); ?></span></p>
<?php else : ?>
<h3 class="title"><a href="#" rel="bookmark">未找到</a></h3>
<p>沒有找到任何文章!</p>
<?php endif; ?>
</div>
<?php
/*
have_posts(); 判斷是否有下一個(gè)文章
the_post(); 改變當(dāng)前文章指向到下一個(gè)文章
the_permalink(); 當(dāng)前指向文章的連接地址
the_title(); 當(dāng)前指向文章的標(biāo)題
the_tags('標(biāo)簽:'); 當(dāng)前指向文章的標(biāo)簽
comments_popup_link('0 條評(píng)論', '1 條評(píng)論', '% 條評(píng)論', '', '評(píng)論已關(guān)閉'); 顯示打印當(dāng)前指向文章的評(píng)論鏈接
edit_post_link('編輯', ' • ', ''); 當(dāng)前指向文章,顯示打印當(dāng)前指向文章的編輯鏈接
the_excerpt(); 當(dāng)前指向文章,只要在寫文章的時(shí)候在"摘要"框內(nèi)填寫摘要,在首頁(yè)顯示的就是摘要,如果不填就輸出全文!
the_content('閱讀全文...'); 用于輸出當(dāng)前指向文章全文,除非在文章中使用了<!-- more -->
the_permalink(); 返回當(dāng)前指向文章閱讀全文的連接地址
previous_posts_link('<< 查看新文章', 0); 顯示打印當(dāng)前顯示列表分頁(yè)連接(每頁(yè)文章數(shù)量取決于在后臺(tái)設(shè)置每頁(yè)可顯示的文章數(shù)量)
next_posts_link('查看舊文章 >>', 0); 顯示打印當(dāng)前顯示列表分頁(yè)連接
the_time('Y年n月j日');顯示日期如 1999年5月1日
另外,還有個(gè)存檔頁(yè)面的模板archive.php,跟index.php的制作過(guò)程完全一樣,只不過(guò)需要在functions.php里添加一個(gè)函數(shù)
單文章頁(yè)single.php,可以根據(jù)index.php頁(yè)往這里添加自己想要顯示的內(nèi)容
page.php 也就是頁(yè)面,博客上的所有網(wǎng)頁(yè)都是頁(yè)面,這里指的頁(yè)面一個(gè)單獨(dú)的頁(yè)面,如"關(guān)于"、"聯(lián)系方式"等,可以在WordPress后臺(tái) 主站蜘蛛池模板: 亚洲福利在线观看 | 91av国产在线 | 蜜月aⅴ免费一区二区三区 免播放器在线观看 | 欧美另类xxx精品人妖 | 丁香六月激情综合 | 91精品91| 日韩在线播放中文字幕 | 狠狠色综合网 | 国产亚洲精品九九久在线观看 | 免费视频黄 | 国产久热香蕉在线观看 | 丁香婷婷久久大综合 | 欧美日韩一二三区 | 亚洲精品福利视频 | 国产精品欧美亚洲韩国日本不卡 | 国产精品视频网 | 久久精品国产清自在天天线 | 手机在线日韩高清理论片 | 日韩精品一区二区三区在线观看 | 中文字幕在线精品 | 污视频免费在线播放 | 国产第一区二区三区在线观看 | 国内精品久久久久久野外 | 国产精品视频一区二区猎奇 | 国产91观看 | 欧美激情 亚洲 | 韩国理伦一级毛片 | 国产精品香蕉在线一区 | 天天澡天天摸天天爽免费 | 无遮挡一级毛片 | 婷婷久久综合 | 天天综合干| 好吊妞视频在线观看 | 久久精品国产清自在天天线 | 国产大片中文字幕在线观看 | 五月婷久久| 黄色小视频在线观看 | 久久不卡精品 | 久久久久久久综合日本亚洲 | 99久草| 色一色在线观看视频网站 |