記錄在開發過程中常用的
引入標簽:在一個模板文件里引用另外一個文件
- get_header()
- get_footer()
- get_sidebar()
- get_template_part()
- get_search_form()
- comments_template() ----引入評論框
<?php //調用header.php get_header(); //調用header-one.php get_header('one'); ?>
<?php //調用header.php get_template_part('header'); //調用header-one.php get_template_part('header','one'); ?>
<?php get_search_form(); //等同 get_search_form(true); //為false時是賦值,需要另外輸出 $form=get_search_form(false); echo $form; ?>
模版標簽:
- bloginfo()
- wp_title()
- the_title()
- the_permalink()
- the_content()
- the_excerpt()
- the_category()
- the_tags()
- the_time()
- comments_popup_link() ----評論條數
- edit_post_link()
- next_post_link()
- previous_post_link()
bloginfo() 顯示博客信息,用法:
<h1><?php bloginfo( 'name' ); ?></h1>
<p><?php bloginfo('description'); ?> </p>
參數:
admin_email = admin@example.com atom_url = http://www.example.com/home/feed/atom charset = UTF-8 comments_atom_url = http://www.example.com/home/comments/feed/atom comments_rss2_url = http://www.example.com/home/comments/feed description = Just another WordPress blog home = http://www.example.com/home (DEPRECATED! use url option instead) html_type = text/html language = en-US name = Testpilot pingback_url = http://www.example.com/home/wp/xmlrpc.php rdf_url = http://www.example.com/home/feed/rdf rss2_url = http://www.example.com/home/feed rss_url = http://www.example.com/home/feed/rss siteurl = http://www.example.com/home (DEPRECATED! use url option instead) stylesheet_directory = http://www.example.com/home/wp/wp-content/themes/largo stylesheet_url = http://www.example.com/home/wp/wp-content/themes/largo/style.css template_directory = http://www.example.com/home/wp/wp-content/themes/largo template_url = http://www.example.com/home/wp/wp-content/themes/largo text_direction = ltr url = http://www.example.com/home version = 3.5 wpurl = http://www.example.com/home/wp
wp_title()
用途:通常用在頁面頭部的<title>元素中,在不同文件里,返回的值不一樣,具體如下:
文章頁->文章標題
日期頁->日期
分類頁->分類標題
作者頁->作者名字
用法:
<?php wp_title( $sep, $display, $seplocation ); ?>
$sep--分隔符,$display--是否直接顯示(不直接顯示需要echo才出來),$seplocation--分隔符所在位置
the_title()
<?php the_title( $before, $after, $echo ); ?>
參數說明:$before 標題前,$after標題后, $echo是否直接輸出
用途:需放主循環內,調用發布信息的標題,在不同文件里,返回的值不一樣。
<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?> <!-- 在這里調用數據 --> <?php the_title();?> <?php endwhile; ?> <?php endif; ?>
the_permalink()
用途:調用當前信息的網址,必須在主循環內使用
<?php the_permalink(); ?>
the_content()
用途:顯示內容,
如果文章插入了more標簽


<?php the_content( 'Read more ...' ); ?>
有參數的情況下:

the_excerpt()
用途:調用摘要,如果沒有填寫摘要則截取文章前55個字符
<?php the_excerpt(); ?>
the_category()
用途:調用當前文章所屬分類,必須在主循環內使用
<?php the_category( $separator, $parents, $post_id ); ?>
參數說明:$separator--分隔符,$parents---父目錄控制,$post_id---文章編號
只輸出當前文章目錄:
<?php the_category(); ?>
去格式化輸出當前文章目錄:
<?php the_category('|'); ?>
子目錄和父目錄一起調出:
<?php the_category('|','multiple'); ?>
the_tags()
用途:調用當前分類所用的標簽
<?php the_tags( $before, $sep, $after ); ?>
參數說明:$before---標簽前,$sep--分隔符,$after---標簽后
the_time()
用途:調用發表時間,*需放在主循環內
<?php the_time( $d ); ?>
參數說明:$d---時間顯示格式
<?php the_time('Y-m-d h:i'); ?>
輸出:2017-01-28 12:09
comments_popup_link()
用途:調用評論條數,並帶跳轉到該文章的評論框的鏈接,必須在主循環內使用
<?php comments_popup_link( $zero, $one, $more, $css_class, $none ); ?>
參數說明:$zero--沒評論的時候顯示什么,$one---一條評論的時候顯示什么,$more---更多評論的時候顯示什么,$css_class---鏈接的css類,$none---文章不允許評論時顯示什么
edit_post_link()
用途:有權限編輯文章時顯示的編輯鏈接,必須在主循環內使用
<?php edit_post_link( $link, $before, $after, $id, $class ); ?>
參數說明:$link---鏈接文本,$before---鏈接文本前的文本,$after---鏈接文本后的文本,$id---文章ID,$class---鏈接樣式
next_post_link(),previous_post_link()
用途:必須在主循環內使用
<?php next_post_link("上一篇: %link") ?>
<?php previous_post_link("下一篇: %link") ?>
更多請參考文檔,推薦英文版
wordpress函數參考:
英文官方參考網頁:http://codex.wordpress.org/Function_Reference/
中文官方參考網頁:http://codex.wordpress.org.cn/%E5%87%BD%E6%95%B0%E5%8F%82%E8%80%83
wordpress模版標簽:
英文官方參考網頁:http://codex.wordpress.org/Template_Tags/
中文官方參考網頁:http://codex.wordpress.org.cn/%E6%A8%A1%E6%9D%BF%E6%A0%87%E7%AD%BE
wordpress引入標簽:
英文官方參考網頁:http://codex.wordpress.org/Include_Tags
中文官方參考網頁:http://codex.wordpress.org.cn/Include_Tags
wordpress條件標簽:
英文官方參考網頁:http://codex.wordpress.org/Conditional_Tags
中文官方參考網頁:http://codex.wordpress.org.cn/%E6%9D%A1%E4%BB%B6%E6%A0%87%E7%AD%BE
