二十四、Wordpress模板判断函数,怎么判断不同页面模板

admin2017-08-241422

blob.png

is_home()    //判断是否在首页

wp_title()    //自动识别模板,返回对应标题

$paged    //全局变量,判断是否为分页

is_category()    //判断是否是分类页面

is_search()    //判断是否是搜素页面

is_404()    //判断是否是404页面

is_single()    //判断是否是文章页面

is_page()    //判断是否是单页页面

<!doctype html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=<? echo get_bloginfo('charset'); ?>" />
    
    <?
        if( is_home() ){ $title = get_bloginfo('name'); }    //判断是否在首页,显示首页标题
        else{ $title = wp_title( '', false ) . "_黄聪的博客"; }//自动识别模板,返回对应标题
        
        if( $paged > 0 ){ $title .= "-第" . $paged . "页"; }    //判断是否为分页
    ?>
    <title><? echo $title; ?></title>
    
    <? if( is_home() ){ ?>    <!--判断是否在首页-->
    <meta name="description" content="<? bloginfo('description'); ?>" />
    <? } ?>
    <link rel="stylesheet" href="<? bloginfo('stylesheet_url'); ?>" type="text/css" />
    <script type="text/javascript" src="<? bloginfo('template_directory');?>/js/jquery-1.8.3.min.js"></script>
    <!--判断是否是分类页面-->
    <? if( is_category() ){ ?><link rel="stylesheet" href="<? bloginfo('template_directory');?>/style-cat.css" type="text/css" /><? } ?>
    <!--判断是否是搜素页面-->
    <? if( is_search() ){ ?><link rel="stylesheet" href="<? bloginfo('template_directory');?>/style-search.css" type="text/css" /><? } ?>
    <!--判断是否是404页面-->
    <? if( is_404() ){ ?><link rel="stylesheet" href="<? bloginfo('template_directory');?>/style-404.css" type="text/css" /><? } ?>
    <!--判断是否是文章页面-->
    <? if( is_single() ){ ?><link rel="stylesheet" href="<? bloginfo('template_directory');?>/style-single.css" type="text/css" /><? } ?>
    <!--判断是否是单页页面-->
    <? if( is_page() ){ ?><link rel="stylesheet" href="<? bloginfo('template_directory');?>/style-page.css" type="text/css" /><? } ?>
    
    <? wp_head(); ?>
</head>


网友评论