WordPress常用标签和调用总结
调用头部模板
<?php get_header();?>
调用尾部模板
<?php get_footer();?>
调用侧边栏
<?php get_sidebar();?>
放在head标签内,方便插件调用:
<?php wp_head(); ?>
放在footer里,body结束之前,方便插件调用:
<?php wp_footer(); ?>
----------------------------------------------------------
头部编码调用:
<meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
头部css调用:
<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" type="text/css" media="screen" />
style.css路径调用:
<?php bloginfo( 'stylesheet_url' ); ?>
博客标题:
<?php bloginfo('name'); ?>
博客副标题:
<?php bloginfo('description'); ?>
主页地址:
<?php echo get_option('home'); ?>
或
<?php bloginfo('home'); ?>
主题模板所在路径:
<?php bloginfo('template_directory'); ?>
----------------------------------------------------------
page页面列表:
<?php wp_list_pages('sort_column=menu_order&title_li=&depth=2&include='); ?>
分类目录列表:
<?php wp_list_categories('title_li=&orderby=name&show_count=0&depth=2'); ?>
----------------------------------------------------------
主循环的开始和结束:
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
文章的URL地址:
<?php the_permalink() ?>
文章标题:
<?php the_title(); ?>
文章内容:
<?php the_content('Read more...'); ?>
文章摘要:
<?php the_excerpt(); ?>
文章所在分类:
<?php the_category(', ') ?>
文章发布时间:
<?php the_time('Y-m-d') ?>
文章作者:
<?php the_author_posts_link(); ?>
文章评论数量:
<?php comments_number('No comment', '1 comment', '% comments'); ?>
文章标签:
<?php the_tags( 'Tags: ', ', '); ?>
文章评论:
<?php comments_template(); ?>
多页型文章的翻页按钮(调用:<!--nextpage-->):
<?php wp_link_pages(); ?>
----------------------------------------------------------
小工具边栏调用:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?>
<?php endif; ?>
小工具动态边栏注册(functions.php):
<?php
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name'=>'Sidebar',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));}
?>
自定义菜单调用:
<?php wp_nav_menu(array('theme_location' => 'primary')); ?>
自定义菜单注册(functions.php):
<?php register_nav_menu('primary',__('Primary Navigation')); ?>
----------------------------------------------------------
最新文章列表:
<?php wp_get_archives('type=postbypost&limit=10'); ?>
文章按月归档列表:
<?php wp_get_archives('type=monthly'); ?>
RSS地址:
<?php bloginfo('rss2_url'); ?>
标签云:
<?php wp_tag_cloud('smallest=8&largest=32'); ?>
友情链接:
<?php wp_list_bookmarks(); ?>
翻页插件按钮调用:
<?php if(function_exists('wp_pagenavi')) wp_pagenavi(); ?>
列表页面的上一页下一页调用:
<span class="older"><?php previous_posts_link() ?></span>
<span class="newer"><?php next_posts_link() ?></span>
文章页面的上一篇下一篇调用:
<span class="older"><?php previous_post_link(); ?></span>
<span class="newer"><?php next_post_link(); ?></span>
缩略图调用:
<?php the_post_thumbnail(); ?>
缩略图功能启用(functions.php):
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 200, 150, true ); // 普通的缩略图
搜索框调用:
<?php get_search_form(); ?>
在分类页面显示分类名称:
<?php single_cat_title(); ?>
----------------------------------------------------------
style.css版权信息
/*
Theme Name: wpcourse theme
Theme URI: http://www.pprar.com
Description: wpcourse blog theme
Author: ralph
Author URI: http://www.99jianzhu.com
Version: 1.0
Tags: white, simple, blog, wpcourse
*/
----------------------------------------------------------
更多wordpress标签参考:
http://codex.wordpress.org/Function_Reference
----------------------------------------------------------
WP Kit CN 中文工具箱插件可直接调用的标签:
<?php wkc_recent_posts() ?> 显示最新文章
<?php wkc_random_posts() ?> 显示随机文章
<?php wkc_related_posts() ?> 显示相关文章
<?php wkc_posts_in_the_same_categories() ?> 输出同一个分类下的文章
<?php wkc_most_commented_posts() ?> 显示评论最多的文章
<?php wkc_recent_comments() ?> 显示最新评论
<?php wkc_recent_pings() ?> 显示最新pingback和trackback
<?php wkc_most_active_commentors() ?> 显示n天内,评论最多的用户
<?php wkc_recent_commentors() ?> 显示本周或者本月内评论最多的用户
使用说明:
http://sexywp.com/wp-kit-cn-doc
----------------------------------------------------------
调用最新文章列表(方法2):
<?php
$args = array( 'numberposts' => '10' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> ';
}
?>
----------------------------------------------------------
调用某个分类下的最新文章列表:
<?php
$args = array( 'numberposts' => '5','category'=>'41' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '">'.$recent["post_title"].'</a></li> ';
}
?>
调用某个分类下的最新文章列表(方法2):
<ul>
<?php
global $post;
$args = array( 'numberposts' => 5, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
调用某个分类下置顶的文章列表:
<?php
$args = array( 'numberposts' => '5','category'=>'41' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
if (is_sticky($recent["ID"])) {
echo '<li><a href="' . get_permalink($recent["ID"]) . '">'.$recent["post_title"].'</a></li> ';
}
}
?>
----------------------------------------------------------
面包屑导航:
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
----------------------------------------------------------
在分类页面显示子分类列表:
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC',
'child_of' => 1
);
$categories=get_categories($args);
foreach($categories as $category) {
echo '<li class="nav2">
<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>
</li>';
}
?>
----------------------------------------------------------
热评文章列表(functions.php):
<?php function simple_get_most_viewed($posts_num=10, $days=30){
global $wpdb;
$sql = "SELECT ID , post_title , comment_count
FROM $wpdb->posts
WHERE post_type = 'post' AND TO_DAYS(now()) - TO_DAYS(post_date) < $days
ORDER BY comment_count DESC LIMIT 0 , $posts_num ";
$posts = $wpdb->get_results($sql);
$output = "";
foreach ($posts as $post){
$output .= "\n<li><a href= \"".get_permalink($post->ID)."\" rel=\"bookmark\" title=\"".$post->post_title." (".$post->comment_count."条评论)\" >".$post->post_title."</a> </li>";
}
echo $output;
}
?>
----------------------------------------------------------
随机文章列表:
<?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;?>
分类页面调用缩略图(wp_thumbnails插件):
<?php if(function_exists('wp_thumbnails_for_category')) { wp_thumbnails_for_category(); } ?>
WordPress常用标签和调用总结的更多相关文章
- windows server 2008 r2 启用索引(转)
08r2的“windows search”服务默认是不安装的,要想启用索引执行下列步骤: 1.打开“服务器管理”——选中“角色”——右边选中“添加角色”——勾选“文件服务”. 2. ...
- 【R笔记】R语言函数总结
R语言与数据挖掘:公式:数据:方法 R语言特征 对大小写敏感 通常,数字,字母,. 和 _都是允许的(在一些国家还包括重音字母).不过,一个命名必须以 . 或者字母开头,并且如果以 . 开头,第二个字 ...
- 【R笔记】R语言进阶之4:数据整形(reshape)
R语言进阶之4:数据整形(reshape) 2013-05-31 10:15 xxx 网易博客 字号:T | T 从不同途径得到的数据的组织方式是多种多样的,很多数据都要经过整理才能进行有效的分析,数 ...
- Python获取爬虫数据, r.text 与 r.content 的区别
1.简单粗暴来讲: text 返回的是unicode 型的数据,一般是在网页的header中定义的编码形式. content返回的是bytes,二级制型的数据. 如果想要提取文本就用text 但是如果 ...
- R语言 启动报错 *** glibc detected *** /usr/lib64/R/bin/exec/R: free(): invalid next size (fast): 0x000000000263a420 *** 错误 解决方案
*** glibc detected *** /usr/lib64/R/bin/exec/R: free(): invalid next size (fast): 0x000000000263a420 ...
- velecity报错:Caused by: org.apache.velocity.exception.ParseErrorException: Lexical error, Encountered: <EOF> after : "\'/order/pay?activity=\" + activityId);\r\n }*/\r\n</script>\r\n#end\r\n" at /a
Caused by: org.apache.velocity.exception.ParseErrorException: Lexical error, Encountered: <EOF> ...
- Android中View自己定义XML属性具体解释以及R.attr与R.styleable的差别
为View加入自己定义XML属性 Android中的各种Widget都提供了非常多XML属性,我们能够利用这些XML属性在layout文件里为Widget的属性赋值. 例如以下所看到的: <Te ...
- 批量修改文件权限 和所有者 chown nobody:nobody * -R chmod 775 * -R
chown nobody:nobody * -R chmod 775 * -R
- SQL_Server_2008定期自动备份详细图解
SQL_Server_2008定期自动备份详细图解 设置自动数据库的定期备份计划. http://wenku.baidu.com/link?url=Tu ...
随机推荐
- Java遍历总结:for、for each和迭代器iterator
一.for,for each和iterator用法和区别: 相同点: 三个都可以用来遍历数组和集合 不同点: 1.形式差别 //for的形式是 ;i<arr.size();i++){...} ...
- iOS开发- 自己主动消失的弹出框
- (void)timerFireMethod:(NSTimer*)theTimer//弹出框 { UIAlertView *promptAlert = (UIAlertView*)[theTimer ...
- 安装Scala 找不到或无法加载主类 scala.tools.nsc.MainGenericRunner 错误
对于安装Scala时 找不到或无法加载主类 scala.tools.nsc.MainGenericRunner 错误,不管是linux还是window系统,原因很大可能是scala的安装路径中出现空格 ...
- easyUI表头样式
easyUI表头样式 学习了:https://blog.csdn.net/lucasli2016/article/details/53606609 easyUI的样式定义在easyui.css中 表头 ...
- Java实现算法之--选择排序
选择排序也是比較简单的一种排序方法,原理也比較easy理解,它与冒泡排序的比較次数同样,但选择排序的交换次数少于冒泡排序.冒泡排序是在每次比較之后,若比較的两个元素顺序与待排序顺序相反,则要进行交换, ...
- nginx 配置优化详解
# nginx不同于apache服务器,当进行了大量优化设置后会魔术般的明显性能提升效果 # nginx在安装完成后,大部分参数就已经是最优化了,我们需要管理的东西并不多 #user nobody; ...
- git删除历史
Git如何永久删除文件(包括历史记录) 有些时候不小心上传了一些敏感文件(例如密码), 或者不想上传的文件(没及时或忘了加到.gitignore里的), 而且上传的文件又特别大的时候, 这将导致别 ...
- centos 6.5 python2.6.6 zbar 安装
经过数次折腾,终于搞明白了这个zbar的安装顺序. 1.先安装http://zbar.sourceforge.net/download.html 下的zbar, 2.python 安装z ...
- BigInteger 与 BigDecimal区别,及BigDecimal详解
一般来说,BigInteger用的不是很多,BigDecimal用的稍微多一点,就比如说JDBC中,如果一个字段的数据库类型是Number, 那么getObject().getClass()的结果是j ...
- c++ builder xe2 字符串转日期
TFormatSettings * fmt = new TFormatSettings; fmt->ShortDateFormat = L"yy-mm-dd"; fmt-&g ...