1
2
3
4
5
6
7
8
9
10
11
12
<?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)的标题

wordpress主题位置调用

1
<?php bloginfo('template_url'); ?>

wordpress缩略图

1
<?php if(has_post_thumbnail()){the_post_thumbnail(array(180,130));}else{echo '<img class="small_img" src="" style="opacity: 1.1; background: rgb(255, 255, 255) none repeat scroll 0% 0%;">';}?>
1
2
3
4
5
6
the_post_thumbnail();// 没有输入参数,默认是 -> 'post-thumbnail'
the_post_thumbnail('thumbnail');// Thumbnail (默认最大是 150px x 150px)
the_post_thumbnail('medium');// Medium resolution (默认最大是 300px x 300px)
the_post_thumbnail('large');// Large resolution (默认最大是 640px x 640px)
the_post_thumbnail('full');// Full resolution (原始上传图片的大小)
the_post_thumbnail( array(100,100));// 其他尺寸

wordpress调用子分类

1
<?php wp_list_categories('hide_empty=0&child_of=32&exclude=&title_li='); ?>

wordpress获取指定分类链接方法

1
<?php $catlink=get_category_link(12); echo $catlink ?>

wordpress判断当前分类输出下级分类

1
2
3
4
5
6
7
<?php
$cat= single_cat_title('', false);
$catid = get_cat_ID($cat);
if($catid == 14){$catid = 10;};
wp_list_categories('hide_empty=0&child_of='.$catid.'&exclude=&title_li=');

?>

wordpress在任意页面调用指定分类的文章

1
2
3
4
5
<?php
query_posts('showposts=6&cat=6');
while(have_posts()) : the_post();
?>
<?php endwhile; ?>

wordpress主题头部和底部必须添加的钩子

1
2
<?php wp_footer();?>
<?php wp_head();?>

wordpress调用菜单

1
<?php wp_nav_menu(array('theme_location'=>'primary','container'=>'div','container_id'=>'nav','container_class'=>'nav','menu_class'=>'nav_content','menu_id'=>'nav_content'));?>

wordpress调用搜索

1
<?php get_search_form();?>

wordpress标题格式

1
2
3
4
<?php if(is_single()){single_post_title(); bloginfo('name');}elseif (is_home()){ bloginfo('name');echo "-";bloginfo('description');}elseif(is_front_page()){ bloginfo('name');$paged = get_query_var('paged'); if($paged>1) printf('–第%s页',$paged); echo '-';bloginfo('name');}elseif(is_page()){single_post_title(''); echo ' | '; bloginfo('name');}elseif(is_search()){printf( __('Search results for "%s"','iLost'),esc_html($s));echo ' | '; bloginfo('name');}elseif(is_404()){echo '你访问的页面不存在';echo ' | '; bloginfo('name');}else{wp_title('');echo "-";bloginfo('name');} ?>

<?php bloginfo('description'); ?>
<?php bloginfo('template_url'); ?>

reg nav

1
2
3
4
5
6
if (function_exists('register_nav_menus')){
register_nav_menus( array(
'nav' => __('网站导航', 'haoui'),
'topmenu' => __('顶部菜单', 'haoui')
));
}

reg sidebar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
if (function_exists('register_sidebar')) {
$sidebars = array(
'gheader' => '公共头部',
'gfooter' => '公共底部',
'home' => '首页',
'cat' => '分类页',
'tag' => '标签页',
'search' => '搜索页',
'single' => '文章页'
);
foreach ($sidebars as $key => $value) {
register_sidebar(array(
'name' => $value,
'id' => $key,
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
};
}

添加文章形式

1
add_theme_support( 'post-formats', array( 'aside' ) );

post thumbnail

1
2
3
4
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
set_post_thumbnail_size(220, 150, true );
}