本文以技術手冊的方式簡單匯總WordPress主題模板的基本資料,希望能對WordPress主題模板開發的朋友解渴。
WordPress 主題模板基本文件
一套完整的 WordPress 主題模板應至少具有如下文件:,WordPress基本模板文件,WordPress模板必備文件:
style.css : CSS(樣式表)文件index.php : 主頁模板archive.php : Archive/Category模板404.php : Not Found 錯誤頁模板comments.php : 留言/回復模板footer.php : Footer模板header.php : Header模板sidebar.php : 側欄模板page.php : 內容頁(Page)模板single.php : 內容頁(Post)模板searchform.php : 搜索表單模板search.php : 搜索結果模板
基本條件判斷Tag
is_home() : 是否為主頁is_single() : 是否為內容頁(Post)is_page() : 是否為內容頁(Page)is_category() : 是否為Category/Archive頁is_tag() : 是否為Tag存檔頁s_date() : 是否為指定日期存檔頁is_year() : 是否為指定年份存檔頁is_month() : 是否為指定月份存檔頁is_day() : 是否為指定日存檔頁is_time() : 是否為指定時間存檔頁is_archive() : 是否為存檔頁is_search() : 是否為搜索結果頁s_404() : 是否為 “HTTP 404: Not Found” 錯誤頁is_paged() : 主頁/Category/Archive頁是否以多頁顯示
Header部分常用到的html' target='_blank'>PHP函數
<?php bloginfo (’name’); ?> : 博客名稱(Title)<?php bloginfo (’stylesheet_url’); ?> : CSS文件路徑<?php bloginfo (’pingback_url’); ?> : PingBack Url<?php bloginfo (’template_url’); ?> : 模板文件路徑<?php bloginfo (’version’); ?> : WordPress版本<?php bloginfo (’atom_url’); ?> : Atom Url<?php bloginfo (’rss2_url’); ?> : RSS 2.o Url<?php bloginfo (’url’); ?> : 博客 Url<?php bloginfo (’html_type’); ?> : 博客網頁Html類型<?php bloginfo (’charset’); ?> : 博客網頁編碼<?php bloginfo (’description’); ?> : 博客描述<?php wp_title(); ?> : 特定內容頁(Post/Page)的標題
模板常用的PHP函數及命令
<?php get_header(); ?> : 調用Header模板<?php get_sidebar(); ?> : 調用Sidebar模板<?php get_footer(); ?> : 調用Footer模板<?php the_content(); ?> : 顯示內容(Post/Page)<?php the_excerpt(); ?>: 顯示摘要<?php if (have_posts()) : ?> : 檢查是否存在Post/Page<?php while (have_posts()) : the_post(); ?> : 如果存在Post/Page則予以顯示<?php endwhile ; ?> : While 結束<?php endif ; ?> : If 結束<?php the_time(’字符串’) ?> : 顯示時間,時間格式由“字符串”參數決定,具體參考PHP手冊<?php comments_popup_link(); ?> : 正文中的留言鏈接。如果使用 comments_popup_script() ,則留言會在新窗口中打開,反之,則在當前窗口打開<?php the_title(); ?> : 內容頁(Post/Page)標題<?php the_permalink() ?> : 內容頁(Post/Page) Url<?php the_category(’, ‘) ?> : 特定內容頁(Post/Page)所屬Category<?php the_author(); ?> : 作者<?php the_ID(); ?> : 特定內容頁(Post/Page) ID<?php edit_post_link(); ?> : 如果用戶已登錄并具有權限,顯示編輯鏈接<?php get_links_list(); ?> : 顯示Blogroll中的鏈接<?php comments_template(); ?> : 調用留言/回復模板<?php wp_list_pages(); ?> : 顯示Page列表<?php wp_list_categories(); ?> : 顯示Categories列表<?php next_post_link(’ %link ‘); ?> : 下一篇文章鏈接<?php previous_post_link(’%link’); ?> : 上一篇文章鏈接<?php get_calendar(); ?> : 日歷<?php wp_get_archives() ?> : 顯示內容存檔<?php posts_nav_link(); ?> : 導航,顯示上一篇/下一篇文章鏈接<?php include (TEMPLATEPATH . ‘/文件名’); ?> : 嵌入其他文件,可為定制的模板或其他類型文件
與模板相關的其他函數
<?php _e(’Message’); ?> : 輸出相應信息<?php wp_register(); ?> : 顯示注冊鏈接<?php wp_loginout(); ?> : 顯示登錄/注銷鏈接<–next page–> : 將當前內容分頁<–more–> : 將當前內容截斷,以不在主頁/目錄頁顯示全部內容<?php timer_stop(1); ?> : 網頁加載時間(秒)<?php echo get_num_queries(); ?> : 網頁加載查詢量
其它
<?php get_archives(’postbypost’, 10); ?> 調用最近的10篇日志<?php$rand_posts = get_posts(’numberposts=10&orderby=rand’);foreach ( $rand_posts as $post ) :?><li><a href= "”<?php" the_permalink();= "" ?= "" >”><?php the_title(); ?></a></li><?php endforeach ; ?>
隨機調用10篇日志
<?php the_tags(’Post Tags :’, ‘, ‘, ‘<br />’); ?> 調用標簽<?php if (get_the_tags()) the_tags(’Tags:’,’,’,’ end ’); ?>
標簽存在時調用
<?php wp_tag_cloud(’smallest=1&largest=9&’); ?> 調用標簽云<?php $posts = get_posts( “category=12&numberposts=4″ ); ?> 獲得4篇12分類中的日志
再來一些更詳細的判斷函數
<?php if (is_single()):?>//這里寫你想顯示的內容,包括函數<?php endif ;?>
下面是直接來自wordpress.org
is_single() 判斷是否是具體文章的頁面is_single(’17′) 判斷是否是具體文章(id=17)的頁面is_single(’Beef Stew’) 判斷是否是具體文章(標題判斷)的頁面is_single(’beef-stew’) 判斷是否是具體文章(slug判斷)的頁面comments_open() 是否留言開啟pings_open() 是否開啟pingis_page() 是否是頁面is_page(’42′) 同single,id判斷,即是否是id為42的頁面is_page(’About Me’) title判斷is_page(’about-me’) slug判斷is_category() 是否是分類is_category(’6′) 同single,id判斷,即是否是id為6的分類is_category(’Cheeses’) title判斷is_category(’cheeses’) slug判斷in_category(’5′) 判斷當前的文章是否屬于分類5is_author() 將所有的作者的頁面顯示出來is_author(’1337′) 顯示author number為1337的頁面is_author(’Elite Hacker’) 通過昵稱來顯示當前作者的頁面is_author(’elite-hacker’)is_date()is_year()is_month()is_day()is_time()is_archive() 判斷當前是否是歸檔頁面is_search() 判斷是否是搜索is_404() 判斷頁面是否404is_paged() 判斷是否翻頁,比如你當前的blog是http: //domain.com,顯示http: //domain.com?paged=2的時候,這個判斷將返回真,通過這個函數可以配合is_home來控制某些只能在首頁顯示的界面,例如: if (is_home() && !is_paged()
以上就是WordPress常用的函數、方法匯總的詳細內容,更多請關注 其它相關文章!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答
圖片精選