我为一个项目创建了几个模板,实际上它是Contrast theme. 在Wordpress CMS中,我可以选择我创建的模板:
http://i.imgur.com/PYKqK.png (不能发布图片,网站说我是个新手……)
在主题的一个函数中(请参见下面的background.php),有以下条件检查:
<?php if (is_page() || is_single()) { ?>
它适用于除两个模板外的所有自定义模板。我知道这两个失败的地方实际上是页面,但是
is_page()
仍然是空的,因此
false
.
我应该寻找什么来确保这两个模板作为页面?还是我应该找别的东西?
下面是两个模板的代码。请记住,我只涉及与内容相关的代码,而不是模板开头的if/else。
页面底部包含一个文件,用于检查is_page()
. 下面也是该文件的代码。
文本内容模板(函数,返回is_page()
):
<?php
/*
Template Name: Textual Content Page
*/
?>
<?php get_header(); ?>
<?php
// transparent_layer
if(meta(array(\'id\' => $post -> ID, \'meta\' => \'transparent_layer\')) == \'0\')
{
if(option(\'transparent_layer\') == \'0\')
{
$transparent = false;
}
elseif(option(\'transparent_layer\') == \'1\')
{
$transparent = true;
}
}
elseif(meta(array(\'id\' => $post -> ID, \'meta\' => \'transparent_layer\')) == \'1\')
{
$transparent = false;
}
elseif(meta(array(\'id\' => $post -> ID, \'meta\' => \'transparent_layer\')) == \'2\')
{
$transparent = true;
}
// content_position
if(meta(array(\'id\' => $post -> ID, \'meta\' => \'content_position\')) == \'0\')
{
if(option(\'content_position\') == \'0\')
{
$content_position = \'0\';
}
elseif(option(\'content_position\') == \'1\')
{
$content_position = \'1\';
}
elseif(option(\'content_position\') == \'2\')
{
$content_position = \'2\';
}
}
elseif(meta(array(\'id\' => $post -> ID, \'meta\' => \'content_position\')) == \'1\')
{
$content_position = \'0\';
}
elseif(meta(array(\'id\' => $post -> ID, \'meta\' => \'content_position\')) == \'2\')
{
$content_position = \'1\';
}
elseif(meta(array(\'id\' => $post -> ID, \'meta\' => \'content_position\')) == \'3\')
{
$content_position = \'2\';
}
//portrait_fit
if(meta(array(\'id\' => $post -> ID, \'meta\' => \'portrait_fit\')) == \'1\')
{
$portrait = \'1\';
}
?>
<!-- content start -->
<div class="content">
<?php get_sidebar(); ?>
<div class="sliderContent">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<div class="content-body">
<?php the_content(__(\'Read More »\', THEMENAME)); ?>
<?php endwhile; else: ?>
<p><?php _e(\'Nothing found.\', THEMENAME); ?></p>
<?php endif; ?>
</div>
</div>
</div>
<!-- content end -->
<?php require_once(TEMPLATEPATH . \'/assets/includes/theme-background.php\'); ?>
<?php get_footer(); ?>
新闻模板(不起作用,不返回值
is_page()
):
<?php
/*
Template Name: News Page
*/
?>
<?php get_header(); ?>
<?php
// transparent_layer
if(meta(array(\'id\' => $post -> ID, \'meta\' => \'transparent_layer\')) == \'0\')
{
if(option(\'transparent_layer\') == \'0\')
{
$transparent = false;
}
elseif(option(\'transparent_layer\') == \'1\')
{
$transparent = true;
}
}
elseif(meta(array(\'id\' => $post -> ID, \'meta\' => \'transparent_layer\')) == \'1\')
{
$transparent = false;
}
elseif(meta(array(\'id\' => $post -> ID, \'meta\' => \'transparent_layer\')) == \'2\')
{
$transparent = true;
}
// content_position
if(meta(array(\'id\' => $post -> ID, \'meta\' => \'content_position\')) == \'0\')
{
if(option(\'content_position\') == \'0\')
{
$content_position = \'0\';
}
elseif(option(\'content_position\') == \'1\')
{
$content_position = \'1\';
}
elseif(option(\'content_position\') == \'2\')
{
$content_position = \'2\';
}
}
elseif(meta(array(\'id\' => $post -> ID, \'meta\' => \'content_position\')) == \'1\')
{
$content_position = \'0\';
}
elseif(meta(array(\'id\' => $post -> ID, \'meta\' => \'content_position\')) == \'2\')
{
$content_position = \'1\';
}
elseif(meta(array(\'id\' => $post -> ID, \'meta\' => \'content_position\')) == \'3\')
{
$content_position = \'2\';
}
// portrait_fit
if(meta(array(\'id\' => $post -> ID, \'meta\' => \'portrait_fit\')) == \'1\')
{
$portrait = \'1\';
}
?>
<!-- content start -->
<div class="content">
<?php get_sidebar(); ?>
<div class="sliderContent">
<h1><?php the_title(); ?></h1>
<div class="content-body news-items-list">
<?php
// loop through posts in news category
// -1 means all posts... not really intuitive
// see http://www.binarymoon.co.uk/2010/03/5-wordpress-queryposts-tips/
$query = array (
\'posts_per_page\' => -1,
\'category_name\' => \'news\'
);
query_posts($query);
while(have_posts()) : the_post();
// get post raw date
$date = get_the_date();
?>
<a
href="<?php the_permalink(); ?>"
class="news-link"
>
<span class="title"><?php the_title(); ?></span>
<span class="date"><?php echo $date; ?></span>
</a>
<?php
endwhile;
?>
</div>
</div>
</div>
<!-- content end -->
<?php require_once(TEMPLATEPATH . \'/assets/includes/theme-background.php\'); ?>
<?php get_footer(); ?>
如您所见,背景。php包含在这些模板的底部。这个文件来自父主题,我没有编辑它。其代码如下:
<!-- loading start -->
<div class="loading">
<img src="<?php bloginfo(\'template_url\'); ?>/assets/images/loading.gif" alt ="Loading" />
</div>
<!-- loading end -->
<!-- background start -->
<div id="background">
<?php if (is_page() || is_single()) { ?>
<?php if (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background\')) == \'1\') { ?>
<style type="text/css">
#background { background: <?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_color\')); ?>; }
</style>
<?php } elseif (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background\')) == \'2\') { ?>
<img src="<?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_image\')); ?>" alt="" class="background" />
<?php } elseif (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background\')) == \'3\') { ?>
<script type="text/javascript">
var flashvars = { flv : \'<?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_flash_video\')); ?>\' };
var params = { wmode: \'transparent\' };
swfobject.embedSWF(\'<?php bloginfo(\'template_url\'); ?>/assets/flash/background.swf\', \'background\', \'100%\', \'100%\', \'9.0.0\', \'expressInstall.swf\', flashvars, params);
</script>
<?php } elseif (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background\')) == \'4\') { ?>
<?php if (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_google_maps_gradient\')) == \'1\') { ?>
<div class="gradient">
<div class="left"> </div>
<div class="right"> </div>
</div>
<?php } ?>
<iframe width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="<?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_google_maps\')); ?>"></iframe>
<?php } elseif (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background\')) == \'5\') { ?>
<script type="text/javascript">
jQuery(function($){
$.supersized({
slide_interval : <?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'slideshow_timeout\')) ?>,
transition : <?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'slideshow_effect\')) ?>,
transition_speed : <?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'slideshow_speed\')) ?>,
slide_links : \'blank\',
slides : [<?php if (meta(array(\'id\' => $post->ID, \'meta\' => \'slideshow_category_type\')) == \'1\') {
$slideshow_categories = \'&slideshow-categories=\' . meta(array(\'id\' => $post->ID, \'meta\' => \'slideshow_category\')); }
query_posts(\'post_type=slideshow\' . $slideshow_categories. \'&orderby=date&showposts=\' . meta(array(\'id\' => $post->ID, \'meta\' => \'slideshow_show_posts\')));
if (have_posts()) { while (have_posts()) { the_post();
$slideshow_images = $slideshow_images . \'{image : \\\'\' . image(array(\'image\' => get_the_post_thumbnail($post->ID), \'tag\' => false)) . \'\\\'},\';
}} wp_reset_query(); echo substr($slideshow_images, 0, -1); ?>]
});
});
</script>
<div id="progress-back" class="load-item">
<div id="progress-bar"></div>
</div>
<?php } elseif (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background\')) == \'6\') { ?>
<video id="video" class="background">
<?php if (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_mp4_video\')) != \'\') { ?>
<source src="<?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_mp4_video\')); ?>" type="video/mp4" />
<?php } ?>
<?php if (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_webm_video\')) != \'\') { ?>
<source src="<?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_webm_video\')); ?>" type="video/webm" />
<?php } ?>
<?php if (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_ogv_video\')) != \'\') { ?>
<source src="<?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_ogv_video\')); ?>" type="video/ogg" />
<?php } ?>
</video>
<script type="text/javascript">
var video = document.getElementById(\'video\');
if (typeof video.loop == \'boolean\') {
video.loop = true;
}
else {
video.addEventListener(\'ended\', function () {
this.currentTime = 0;
this.play();
}, false);
}
video.play();
</script>
<?php } ?>
<?php if (meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_image_pattern\')) == \'1\') { ?>
<div class="pattern pattern-0<?php echo meta(array(\'id\' => $post->ID, \'meta\' => \'post_background_pattern\')); ?>"> </div>
<?php } ?>
<?php } ?>
</div>
<!-- background end -->