天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

基于wordpress主題制作的具體實現步驟

復制代碼 代碼如下:
<?php
/*
在根目錄 -> wp-content -> themes 下創建mytheme文件夾用來存放創建新主題模板

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

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

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

//==================================================header================================================================
可以把網站相同頭內容放在一個頭文件中,在主題目錄下新建 header.php 文件向其中輸入輸入 統一的頭部內容
在 index.php 或想調用該header.php頁面的頁面中 輸入
*/

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

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

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

<?php
/*
顯示菜單欄,這里只在菜單欄中列出分類頁和page頁面,可以根據喜好來列出想要的。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'); //用于列出博客頁面,可不填參數 ?>
</ul>
<?php
//==================================================footer================================================================
/*
footer.php與header.php差不多,寫這個文件的目的也是為了精簡代碼,提高代碼的重用性。
在主題目錄中創建 footer.php ,在 index.php 或想調用該footer.php頁面的頁面中使用
*/
get_footer();//功能和get_header()類似
/*
在footer.php頁面添加 wp_footer提高兼容性
*/
wp_footer();
/*
wp_footer()和wp_head()差不多,都是用于提高主題兼容性,畢竟有很多插件要在頁腳輸出一些東西才能正常工作。
*/
//==================================================sidebar================================================================
/*
在主題目錄下新建 sidebar.php 頁面,在 index.php 或想調用該sidebar.php頁面的頁面中添加
*/
get_sidebar();
/*
調用 sidebar.php 頁面內容
為使WordPress后臺 -> 外觀 -> 小工具,可以正常地拖動小工具到側邊欄
在 sidebar.php 頁面的列表格式應按如下舉例格式
*/
?>
<div>
    <?php
    if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'First_sidebar' )) ://First_sidebar為widget名稱,要和functions.php中對應的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>標簽云</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
/*
同時在主題目錄下創建 functions.php 文件內容為
*/
/** widgets */
if( function_exists('register_sidebar') ) {
    register_sidebar(array(
        'name' => 'First_sidebar', //name就是給widget指定各自的名稱,以便在sidebar.php中分別調用.所以只需要給這兩個widget取兩個名字就好了。
        'before_widget' => '', //定義Widget內容的前后標識符的語句
        'after_widget' => '',
        'before_title' => '<h4>', //定義Widget標題的前后標識符的語句
        '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后臺 -> 外觀 -> 小工具,就可以正常地拖動小工具到側邊欄了

制作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('標簽:', ', ', ''); ?> • <?php the_time('Y年n月j日') ?> • <?php comments_popup_link('0 條評論', '1 條評論', '% 條評論', '', '評論已關閉'); ?><?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();         改變當前文章指向到下一個文章

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

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

單文章頁single.php,可以根據index.php頁往這里添加自己想要顯示的內容

page.php 也就是頁面,博客上的所有網頁都是頁面,這里指的頁面一個單獨的頁面,如"關于"、"聯系方式"等,可以在WordPress后臺

主站蜘蛛池模板: 国产ZZJJZZJJ视频全免费 | 日韩中文亚洲欧美视频二 | 直插下身完整的欧美版 | 欧美人与禽ZOZO性伦交视频 | 麻豆精品人妻一区二区三区蜜桃 | 美女撒尿无遮挡免费中国 | 晚夜免费禁用十大亏亏 | 精品日韩视频 | 全肉高H短篇合集 | 亚洲永久精品ww47app | 龙腾亚洲人成电影网站 | 欧洲xxxxx | 无码国产成人午夜在线观看不卡 | 囯产精品久久久久久久久免费蜜桃 | 青草久久影院 | 亲伦在线观看 | 果冻传媒AV精品一区 | 国产精品视频一区二区猎奇 | 天海翼精品久久中文字幕 | 777黄色片| 国产AV无码一二三区视频 | 亚瑟天堂久久一区二区影院 | 久草在线在线精品观看 | 久久精品国产亚洲AV忘忧草蜜臀 | 91欧美秘密入口 | 久久伊人中文字幕有码 | 性夜a爽黄爽| 16女下面流水不遮图免费观看 | 最新亚洲中文字幕在线观看 | 国产久青青青青在线观看 | 人妖欧美一区二区三区四区 | 国产无遮挡又黄又爽在线视频 | 亚洲成人中文 | 双性大乳浪受噗呲噗呲h总 双性被疯狂灌满精NP | 小小水蜜桃视频高清在线播放 | 免费人成网站在线观看10分钟 | 永久免费看mv网站入口 | 国产AV视频二区在线观看 | 熟女少妇内射日韩亚洲 | 夜夜澡人人爽人人喊_欧美 夜夜骑夜夜欢 | 成人国产精品免费网站 |