如果想要学习和研究wordpress主题,首先去了解一下wordpress基础的模板文件构成是非常必要的,另外就是熟练掌握wordpress常用的一些函数,对我们进行wordpress主题开发是非常有用的。本篇文章就帮助大家把wordpress的基础模板文件以及常用的函数汇总了一下,方便大家在研究wordpress主题或者进行wordpress主题开发过程中进行查询和参考。
wordpress主题的基本模板文件汇总
文件名
描述
style.css
index.PHP
header.PHP
头部模板文件
single.PHP
archive.PHP
searchform.PHP
search.PHP
comments.PHP
留言模板文件
footer.PHP
sidebar.PHP
page.PHP
front-page.PHP
tag.PHP
category.PHP
函数名
描述
<?PHP site_url(); ?>
<?PHP wp_title(); ?>
<?PHP bloginfo(‘name’); ?>
<?PHP bloginfo(‘description’); ?>
站点描述
<?PHP get_stylesheet_directory(); ?>
样式文件所在目录
<?PHP bloginfo(‘stylesheet_url’); ?>
<?PHP bloginfo(‘pingback_url’); ?>
pingback 链接
<?PHP bloginfo(‘template_url’); ?>
<?PHP bloginfo(‘version’); ?>
wordpress 版本
<?PHP bloginfo(‘atom_url’); ?>
atom 链接
<?PHP bloginfo(‘RSS2_url’); ?>
<?PHP bloginfo(‘url’); ?>
网站根链接
<?PHP bloginfo(‘html_type’); ?>
html 版本
<?PHP bloginfo(‘charset’); ?>
字符集
<?PHP wp_nav_menu(); ?>
指定的导航菜单
<?PHP wp_nav_menu( array(‘menu’ => ‘Project Nav’ )); ?>
基于分类的导航
<ul id=”menu”>
<li <?PHP if(is_home()) { ?> class=”current-cat” <?PHP } ?>>
<a href=”<?PHP bloginfo(‘home’); ?>”>Home</a></li>
<?PHP wp_list_categories(‘title_li=&orderby=id’);?>
</ul>
基于页面的导航
<ul id=”menu”>
<li <?PHP if(is_home()) { ?> class=”current-page-item” <?PHP } ?>>
<a href=”<?PHP bloginfo(‘home’); ?>”>Home</a></li>
<?PHP wp_list_pages(‘sort_column=menu_order&depth=1&title_li=’);?>
</ul>
函数名
描述
<?PHP the_content(); ?>
<?PHP if(have_posts()): ?>
检查是否有文章
<?PHP while(have_posts()): the_post(); ?>
<?PHP endwhile; ?>
结束循环
<?PHP endif; ?>
结束判断
<?PHP get_header(); ?>
头部模板内容
<?PHP get_sidebar(); ?>
<?PHP get_footer(); ?>
<?PHP the_time(‘m-d-y’); ?>
显示时间,格式为:’08-18-07′
<?PHP comments_popup_link(); ?>
<?PHP the_title(); ?>
<?PHP the_permalink(); ?>
<?PHP the_category(); ?>
<?PHP the_author(); ?>
文章作者
<?PHP the_ID(); ?>
文章 ID
<?PHP edit_post_link(); ?>
<?PHP wp_list_bookmarks(); ?>
友情链接列表
<?PHP comments_template(); ?>
留言模板内容
<?PHP wp_list_pages(); ?>
所有页面列表
<?PHP wp_list_categories(); ?>
所有分类列表
<?PHP next_post_link(‘%link’); ?>
<?PHP prevIoUs_post_list(‘%link’); ?>
<?PHP get_calendar(); ?>
<?PHP wp_get_archives(); ?>
存档链接列表
<?PHP posts_nav_link(); ?>
<?PHP rewind_posts(); ?>
重回开头开始第二个循环
基本循环
<?PHP if(have_posts()) { ?>
<?PHP while(have_posts()) { ?>
<?PHP the_post(); ?>
<?PHP // custom post content code for title,excerpt and featured image ?>
<?PHP } // end while ?>
<?PHP } // end if ?>
函数名
描述
/%postname%/
<?PHP include(TEMPLATEPATH . ‘/x’); ?>
<?PHP the_search_query(); ?>
搜索表单返回的值
<?PHP _e(‘Message’); ?>
返回翻译之后的文本
<?PHP wp_register(); ?>
<!–nextpage–>
<!–more–>
管理元链接
<?PHP timer_start(); ?>
开始计时 (header.PHP)
<?PHP timer_stop(1); ?>
停止计时 (footer.PHP)
<?PHP echo get_num_queries(); ?>
函 数 名 称
用 法
说明
is_home()
<?PHP if(is_home())?> true 为首页,false 为第二页
判断是否为第一页
is_paged()
<?PHP if(is_paged())?>
当页面为第二页时,?paged=2
is_single()
<?PHP if(is_single())?>
<?PHP if(is_single(‘标题’))?>文章标题
是否为文章单一页面,如要针对特定文章时,可在()中加入文章的 ID 参数,或标题文字
is_page()
<?PHP if(is_page())?>
是否为分页,与单一页面用法相同,在()中可再针对个別的分页 ID 与标题作判断
is_category()
<?PHP if(is_category())?>
<?PHP if(is_category(2))?>分类 id
<?PHP if(is_category(‘标题’))?>分类标题
<?PHP if(is_category(array(6,7)))?>分类 id 为 6、7
<?PHP if(is_category(array(6,7,’minwt’)))?>分类 id 为 6、7 或 minwt
is_archive()
<?PHP if(is_archive())?>
是否为存档页面
is_search()
<?PHP if(is_search())?>
是否为搜索面
is_404
是否为找不到画面 404
is_tag()
<?PHP if(is_tag())?>
is_date()
<?PHP if(is_date())?>
是否为日期存档页面
is_year()
<?PHP if(is_year())?>
是否为年份存档页面
is_month()
<?PHP if(is_month())?>
是否为月份存档页面
is_day()
<?PHP if(is_day())?>
是否为天存档页面
如果你能熟练的掌握和使用以上函数,我相信你已经可以自己开发一个属于你自己的wordpress主题了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。