激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

DEDECMS|帝國CMS|Discuz|PHPCMS|Wordpress|ZBLOG|ECSHOP|蘋果CMS|極致CMS|CMS系統(tǒng)|

服務(wù)器之家 - 建站程序 - Wordpress - 基于wordpress主題制作的具體實(shí)現(xiàn)步驟

基于wordpress主題制作的具體實(shí)現(xiàn)步驟

2020-03-25 14:35WordPress教程網(wǎng) Wordpress

本篇文章是對wordpress主題制作的具體實(shí)現(xiàn)步驟進(jìn)行了詳細(xì)的分析介紹。需要的朋友參考下

復(fù)制代碼 代碼如下:


<?php
/*
在根目錄 -> wp-content -> themes 下創(chuàng)建mytheme文件夾用來存放創(chuàng)建新主題模板

 

在mytheme目錄下創(chuàng)建 index.php ,style.css 兩個文件,在wp后臺 外觀->主題 中就可以看到剛創(chuàng)建的主題

打開style.css文件輸入
*/
?>
/*
Theme Name: 這里填主題名稱
Theme URI: 這里填主題介紹的網(wǎng)址,沒有就填你的博客網(wǎng)址吧
Description:這里填主題的簡短介紹
Author: 作者名
Author URI: 作者的網(wǎng)址
Version: 版本號
Tags: 標(biāo)簽,多個用半角逗號隔開
*/
<?php
/*
在后臺主題管理中即可看到主題相關(guān)信息,css中主題信息內(nèi)容必須用注釋符號括起來

找一個300*225的png圖片,命名為 screenshot.png 放在主題目錄下(mytheme文件夾中),在主題管理頁中即可看到新建主題的預(yù)覽圖片

//==================================================header================================================================
可以把網(wǎng)站相同頭內(nèi)容放在一個頭文件中,在主題目錄下新建 header.php 文件向其中輸入輸入 統(tǒng)一的頭部內(nèi)容
在 index.php 或想調(diào)用該header.php頁面的頁面中 輸入
*/

get_header(); //get_header()就相當(dāng)于將header.php中的代碼拷貝到當(dāng)前的php文件

/*
在主題管理頁面,該主題實(shí)時預(yù)覽中,默認(rèn)打開的 index.php 頁面中即可引入 header.php 頁面的內(nèi)容
header.php 將會被所有的模板頁面(主頁、分類頁、頁面、標(biāo)簽頁等)所包含,所以 header.php 中代碼應(yīng)該是動態(tài)的。
不同頁面的title都是不一樣,而且title的設(shè)置還會直接影響到SEO的效果,所以這里應(yīng)該謹(jǐn)慎設(shè)置。下面提供一種SEO優(yōu)化的title寫法,
在header.php頁面添加
*/
?>
<title>
<?php
if (is_home ()) { // is_home() 當(dāng)前頁面為主頁時返回true
    bloginfo ( 'name' ); // 返回站點(diǎn)標(biāo)題
    echo " - ";
    bloginfo ( 'description' ); // 返回站點(diǎn)副標(biāo)題,站點(diǎn)描述
} elseif (is_category ()) { // is_category() 當(dāng)前頁面為分類頁時返回true
    single_cat_title ();
    echo " - ";
    bloginfo ( 'name' );
} elseif (is_single () || is_page ()) { // is_single() 當(dāng)前頁面為單文章頁時返回true 。 is_page() 當(dāng)前頁面為單頁面時返回true
    single_post_title ();
} elseif (is_search ()) { // is_search() 當(dāng)前頁面為搜索頁時返回true
    echo "搜索結(jié)果";
    echo " - ";
    bloginfo ( 'name' );
} elseif (is_404 ()) { // is_404() 當(dāng)前頁面為404頁時返回true
    echo '頁面未找到!';
} else {
    wp_title ( '', true );
}
?>
</title>
<?php
/*
 以上添加的php代碼運(yùn)用了條件判斷,針對不同的頁面采用不同title
在 header.php 頁面中添加默認(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文件絕對網(wǎng)址路徑,如
http://localhost/wordpress/wp-content/themes/myTheme/style.css
bloginfo('template_url');返回的是主題目錄的絕對網(wǎng)址路徑,可以用來模板中連接樣式圖片,如
http://localhost/wordpress/wp-content/themes/mytheme
添加 pingback 通告功能,在header.php頁面 <head> 標(biāo)簽中里面添加代碼:
*/
?>
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php
/*
添加訂閱feed鏈接,在header.php頁面 <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 - 所有評論" href="<?php bloginfo('comments_rss2_url'); ?>" />
<?php
/*
添加wp_head,有些插件需要在網(wǎng)頁頭部添加一些js或css,要讓這些插件能夠正常的工作,也讓主題有更好的兼容性,應(yīng)該添加wp_head()函數(shù)
header.php 頁面 <head> 標(biāo)簽中添加
*/
?>

<?php wp_head(); //用于包含WordPress程序輸出頭部信息 ?>

<?php
/*
顯示菜單欄,這里只在菜單欄中列出分類頁和page頁面,可以根據(jù)喜好來列出想要的。header.php中
*/
?>
<ul id="navigation" class="grid_8">
    <?php wp_list_categories(); //用于列出博客分類頁 ?>
    <?php wp_list_pages('depth=1&title_li=0&sort_column=menu_order'); //用于列出博客頁面,可不填參數(shù) ?>
</ul>
<?php
//==================================================footer================================================================
/*
footer.php與header.php差不多,寫這個文件的目的也是為了精簡代碼,提高代碼的重用性。
在主題目錄中創(chuàng)建 footer.php ,在 index.php 或想調(diào)用該footer.php頁面的頁面中使用
*/
get_footer();//功能和get_header()類似
/*
在footer.php頁面添加 wp_footer提高兼容性
*/
wp_footer();
/*
wp_footer()和wp_head()差不多,都是用于提高主題兼容性,畢竟有很多插件要在頁腳輸出一些東西才能正常工作。
*/
//==================================================sidebar================================================================
/*
在主題目錄下新建 sidebar.php 頁面,在 index.php 或想調(diào)用該sidebar.php頁面的頁面中添加
*/
get_sidebar();
/*
調(diào)用 sidebar.php 頁面內(nèi)容
為使WordPress后臺 -> 外觀 -> 小工具,可以正常地拖動小工具到側(cè)邊欄
在 sidebar.php 頁面的列表格式應(yīng)按如下舉例格式
*/
?>
<div>
    <?php
    if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'First_sidebar' )) ://First_sidebar為widget名稱,要和functions.php中對應(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
/*
同時在主題目錄下創(chuàng)建 functions.php 文件內(nèi)容為
*/
/** widgets */
if( function_exists('register_sidebar') ) {
    register_sidebar(array(
        'name' => 'First_sidebar', //name就是給widget指定各自的名稱,以便在sidebar.php中分別調(diào)用.所以只需要給這兩個widget取兩個名字就好了。
        'before_widget' => '', //定義Widget內(nèi)容的前后標(biāo)識符的語句
        'after_widget' => '',
        'before_title' => '<h4>', //定義Widget標(biāo)題的前后標(biāo)識符的語句
        '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后臺 -> 外觀 -> 小工具,就可以正常地拖動小工具到側(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 條評論', '1 條評論', '% 條評論', '', '評論已關(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();       判斷是否有下一個文章
the_post();         改變當(dāng)前文章指向到下一個文章

the_permalink();    當(dāng)前指向文章的連接地址
the_title();        當(dāng)前指向文章的標(biāo)題
the_tags('標(biāo)簽:');  當(dāng)前指向文章的標(biāo)簽
comments_popup_link('0 條評論', '1 條評論', '% 條評論', '', '評論已關(guān)閉');    顯示打印當(dāng)前指向文章的評論鏈接
edit_post_link('編輯', ' • ', '');    當(dāng)前指向文章,顯示打印當(dāng)前指向文章的編輯鏈接
the_excerpt();                 當(dāng)前指向文章,只要在寫文章的時候在"摘要"框內(nèi)填寫摘要,在首頁顯示的就是摘要,如果不填就輸出全文!
the_content('閱讀全文...');    用于輸出當(dāng)前指向文章全文,除非在文章中使用了<!-- more -->
the_permalink();              返回當(dāng)前指向文章閱讀全文的連接地址
previous_posts_link('<< 查看新文章', 0); 顯示打印當(dāng)前顯示列表分頁連接(每頁文章數(shù)量取決于在后臺設(shè)置每頁可顯示的文章數(shù)量)
next_posts_link('查看舊文章 >>', 0);      顯示打印當(dāng)前顯示列表分頁連接
the_time('Y年n月j日');顯示日期如 1999年5月1日

另外,還有個存檔頁面的模板archive.php,跟index.php的制作過程完全一樣,只不過需要在functions.php里添加一個函數(shù)

單文章頁single.php,可以根據(jù)index.php頁往這里添加自己想要顯示的內(nèi)容

page.php 也就是頁面,博客上的所有網(wǎng)頁都是頁面,這里指的頁面一個單獨(dú)的頁面,如"關(guān)于"、"聯(lián)系方式"等,可以在WordPress后臺 – 頁面,進(jìn)行頁面的添加修改等。
可根據(jù)之前函數(shù)添加本頁內(nèi)容
*/
while (have_posts()) :
    the_post(); update_post_caches($posts);
endwhile;
/*
update_post_caches($posts);  該函數(shù)重置文章緩存且未被記錄。僅在頁面的第一次循環(huán)檢索到文章子集時,第二次循環(huán)可執(zhí)行基本循環(huán)。

常用函數(shù)
get_avatar($comment, 48);       獲取評論者的gravatar頭像,尺寸為48 * 48
comment_reply_link()                 回復(fù)留言的鏈接
get_comment_time('Y-m-d H:i');       獲取評論發(fā)布時間
edit_comment_link('修改');           管理員修改評論的鏈接
comment_text()                       輸出評論內(nèi)容

is_user_logged_in()                  判斷用戶是否登錄
wp_login_url( get_permalink() );     博客登錄地址
get_comment_author_link()            用于獲取評論者博客地址
$comment_author                      讀取cookie,如果該用戶之前已經(jīng)發(fā)表過評論則自動幫助用戶填寫用戶名
$comment_author_email                讀取cookie,如果該用戶之前已經(jīng)發(fā)表過評論則自動幫助用戶填寫Email
$comment_author_url                  讀取cookie,如果該用戶之前已經(jīng)發(fā)表過評論則自動幫助用戶填寫博客地址
do_action(‘comment_form', $post->ID) 該函數(shù)為某些插件預(yù)留
wp_logout_url(get_permalink())       退出登錄的鏈接
*/

/*
創(chuàng)建模板文件
*/


/*
 Template Name: 自建模板
*/

/*
 模板文件中添加如上注釋代碼,模板文件名任意,在新建頁面時模板選擇即可顯示 自建模板 來使用此模板
可添加想要的模板樣式及頁面內(nèi)容,新建頁面時只填標(biāo)題不寫內(nèi)容,相當(dāng)創(chuàng)建一個頁面鏈接地址,新建頁面存在 數(shù)據(jù)前綴_posts 表中
獲取到頁面地址后,在寫地址時可在后添加參數(shù),則轉(zhuǎn)到該頁時可通過$_GET,$_POST接收
可以單獨(dú)建一個表存儲地址,及所屬頁面類型,及各頁面子父級關(guān)系,在插件中進(jìn)行控制


wordpress固定鏈接
如果修改wordpress固定鏈接不好用,在apache配置文件 httpd.conf 中打開選項
#LoadModule rewrite_module modules/mod_rewrite.so
把前面 # 去掉,并把所有 AllowOverride None 改成 AllowOverride all
如果不是Apache服務(wù)器,而是用的IIS調(diào)試的話,那就得去安裝一個“ISAPI_Rewrite3_0069_Lite.msi”篩選器,然后在站點(diǎn)設(shè)置里面將PHP置為優(yōu)先級。

創(chuàng)建小工具
在主題目錄下新建自定義文件 mytool.php 文件名任意,內(nèi)容任意
然后在 functions.php 中添加如下代碼
*/
register_sidebar_widget ( "我的小工具", "mytool_fun" ); // "我的小工具"為后臺顯示小工具名稱,mytool_fun為引入自建小工具頁面內(nèi)容的方法名
function mytool_fun() {
    include (TEMPLATEPATH . "/mytool.php");
}
/*
在后臺小工具中即可看到自定義的小工具,添加后,前臺頁面即可看到自建小工具頁面的內(nèi)容
*/
?>

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产精品视频专区 | 日本在线视频免费 | 久久无| 亚洲精品久久久久www | 免费看一级片 | 国产精品久久久久久久久久 | 成人午夜精品 | 婷婷久久影院 | 色成人在线 | 黄色网址进入 | 精品亚洲一区二区 | 久久久www成人免费精品 | 得得啪在线 | 久久精品视频网站 | 免费观看黄视频 | 91短视频在线视频 | 国产精品亚洲精品日韩已方 | 久久99精品久久 | 中国杭州少妇xxxx做受 | 在线观看精品视频 | 亚洲成人综合网站 | 青草久久网 | 成人午夜精品久久久久久久蜜臀 | 午夜爽爽爽男女免费观看hd | 日本久久综合网 | 羞羞网站在线观看入口免费 | 成人国产高清 | 久草在线视频新 | 国产精品久久久久久久亚洲按摩 | 精品一区二区在线观看 | 亚洲国产精品久久久久婷婷老年 | 一本到免费视频 | 极品xxxx欧美一区二区 | 国产午夜免费视频 | 免费一级毛片在线播放不收费 | 国产一级毛片国语版 | 欧美在线观看视频一区二区 | 久久人操 | 久久免费激情视频 | 一区二区美女视频 | 天天鲁在线视频免费观看 |