WordPress页面判断就我们想根据不同的页面,或者分类,去调用不同的参数,或者去显示隐藏某些内容,比如判断如果是首页就调用banner图,不是首页就不调用。wordpress页面判断,根据不同的页面调用不同参数在网站开发中是使用非常广泛,也是常用的功能之一,那么今天我们就来学一下如何使用吧!
1、wordpress页面判断常用函数
<? is_home() ?> 是否在首页
<? is_category() ?> 是否在分类页
<? is_page() ?> 是否在单页
<? is_single() ?> 是否在文章页
<? is_search() ?> 是否在搜索页
<? is_404() ?> 是否在404页
<? is_tag() ?> 是否为标签归档页面
<? is_author() ?> 是否为作者归档页面
<? is_day() ?> 是否为按天归档页面
<?is_sticky() ?> 置顶文章判断。
<? is_single('2')?> 是否在id为2的文章页(括号)
<?php if ( is_category() || is_page() || is_author()){ ?> <?php } ?> 多重判断
2、根据不同的页面调用不同参数案例
<? if(is_home()){?> //如果是首页调用首页tdk
<title><?php echo get_option('seo_title'); ?> </title>
<meta name="keywords" content="<?php echo get_option('seo_keywords'); ?>"/>
<meta name="description" content="<?php echo get_option('seo_description');?>"/>
<? } ?>
<? if(is_category()){?> //如果是分类调用分类tdk
<title><?php echo get_field('seo-title'); ?></title>
<meta name="keywords" content="<?php echo get_field('seo-keywords'); ?>"/>
<meta name="description" content="<?php echo get_field('seo-description');?>"/>
<? } ?>
<? if(is_page()){?> //如果单页就调用tdk
<title><?php echo get_field('seo-title'); ?></title>
<meta name="keywords" content="<?php echo get_field('seo-keywords'); ?>"/>
<meta name="description" content="<?php echo get_field('seo-description');?>"/>
<? } ?>
<? if(is_single()){?> //如果是文章页
<title><?php echo get_field('seo-title'); ?></title>
<meta name="keywords" content="<?php echo get_field('seo-keywords'); ?>"/>
<meta name="description" content="<?php echo get_field('seo-description');?>"/>
<? } ?>