【发布时间】:2015-01-17 08:35:33
【问题描述】:
对于我正在开发的网站,我尝试对令人兴奋的 wordpress 主题 (revera) 进行一些修改。原始代码在存档页面上显示帖子,只有缩略图和帖子标题。以下为原代码:
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<article class="col-sm-3 col-6 portbox post">
<?php $thumb = get_post_thumbnail_id(); $img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big) $image = aq_resize( $img_url, 750, 500, true ); //resize & crop the image ?>
<?php if($image) : ?> <div class="hthumb"> <a href="<?php the_permalink(); ?>"><img class="img-responsive" src="<?php echo $image ?>"/></a> </div> <?php endif; ?> <h3><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></h3>
</article>
<?php endwhile; ?>
现在我在archive.php中做了一个if/else语句(显示在下面),所以某些特定类别的存档页面显示了不同于上面提到的另一个代码。
现在,问题是存档不再正确显示原始代码(存档页面)。我所做的if else语句代码如下(错误应该在“else”之后的部分):
<?php
if ( is_category( 'producten-diensten' ) ) {
echo'
the code for producten-diensten category ';
} else {
//everything else
while ($wp_query->have_posts()) :
$wp_query->the_post();
echo'<article class="col-sm-3 col-6 portbox post">';
$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)
$image = aq_resize( $img_url, 750, 500, true ); //resize & crop the image
if($image) : ;
echo'<div class="hthumb"><a href="' . the_permalink() . '"><img class="img-responsive" src="' . $image . '"/></a></div>';
endif;
echo'<h3><a href="' . the_permalink() . '">' . the_title() . '</a></h3>';
echo'</article>';
endwhile;
}?>
页面 (http://tinyurl.com/of2xslw) 正确显示缩略图,但缩略图应链接到的单个帖子的 URL 显示在缩略图上方。缩略图链接到存档页面而不是单个帖子页面,并且帖子的标题(带有指向单个帖子的永久链接)未显示在缩略图下方。取而代之的是一个奇怪的网址。页面应该是这样的
这里出了什么问题?我希望有人可以帮助我。
【问题讨论】:
标签: php wordpress if-statement