【发布时间】:2012-05-23 23:59:15
【问题描述】:
我正在尝试使用 *is_page()* 在单个模板文件中显示 2 个不同的内容。我的代码如下所示
<?php
if ( is_page('news') ) {
// Insert HTML/PHP for News - code shown below
}
else ( is_page('review') ){
// Insert HTML/PHP for Review - code shown below
}
?>
这对我不起作用...不知道为什么?我已经显示了我尝试在下面插入的新闻/评论代码
用于新闻的 HTML/PHP
<div class="news">
<?php query_posts('cat=-89');?>
<?php while ( have_posts() ) : the_post(); ?>
<article class="summary">
<div class="content_wrap cont_page ">
<header>
<h2> <a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?> </a></h2>
<p> <span class="author">
<?php the_author() ?>
</span><br />
<span class="date">
<?php the_date(); ?>
</span>
</header>
<div class="entry-content">
<?php the_excerpt(); ?>
<?php include('share.php')?>
</div>
<aside class="right">
<?php the_post_thumbnail(); ?>
</aside>
</div>
</article>
<?php
<?php endwhile; ?>
</div>
HTML/PHP 供审查
<div class="review">
<?php query_posts('cat=89,246,247,248');?>
<?php while ( have_posts() ) : the_post(); ?>
<article class="summary
<?php
// Custom posts stylings
if ( has_post_format( 'video' )) {
echo 'video';
} elseif ( in_category('orange') ) {
echo 'orange';
} else {
echo 'white';}
?>
">
<div class="content_wrap cont_page ">
<div class="entry-content">
<?php if ( has_post_format( 'video' )) {
// Get the video URL and put it in the $video variable
$videoID = get_post_meta($post->ID, 'video_url', true);
// Echo the embed code via oEmbed
echo '<iframe src="http://player.vimeo.com/video/'.$videoID.'?title=0&byline=0&portrait=0&color=ffffff" width="405" height="285" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
// echo '<iframe src="http://player.vimeo.com/video/'.$videoID.'" width="405" height="285" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
}
else the_post_thumbnail();
?>
</div>
<aside class="right">
<header>
<h2> <a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?> </a></h2>
</header>
<div class="entry-content">
<?php the_excerpt(); ?>
</div>
<?php include('share.php')?>
</aside>
</div>
</article>
<?php
// DISABLED/S default format
// get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
</div>
【问题讨论】:
-
is_page() 我相信是区分大小写的。所以页面标题需要完全匹配。尝试改用页面 ID。
-
那部分很好,这是因为在 if 语句中不能使用 的语法:-/
标签: php html wordpress templates customization