【发布时间】:2017-06-15 15:18:01
【问题描述】:
我创建的设计将用于显示与其他帖子不同的第一个帖子。没那么容易,因为第一个帖子需要在自己的 div id 里,和其他帖子完全不一样。
这是我目前在wordpress php中使用的代码:
<?php get_header(); ?>
<!-- Begin Content -->
<div id="content-wide">
<div class="post">
<div class="imgwide" style="background: linear-gradient(to bottom, rgba(0,0,0,0) 60%, rgba(0,0,0,0.8)), url(<?php echo catch_that_image() ?>); background-repeat: no-repeat; background-size: 100%; background-position: center;">
<div class="p-heading">
<h1>
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</h1>
<div class="p-content">
Excerpt text of the first post goes here but php the_excerpt doesnt work for this wide paragraph
</div>
</div>
</div>
</div>
</div>
<div id="content-a">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post">
<div class="imgdiv"><a href="<?php the_permalink() ?>"><img src="<?php echo catch_that_image() ?>" width="250"></a></div>
<div class="p-heading">
<h1>
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</h1>
</div>
<div class="p-content">
<?php the_excerpt(); ?>
</div>
<div class="p-info">
<?php the_time('j.m.Y') ?> |
<?php the_category(', '); ?> | <img src="http://www.virmodrosti.com/wp-content/uploads/comments.png" alt="Komentarji" width="26" height="12">
<?php $totalcomments = get_comments_number(); echo $totalcomments; ?>
</div>
</div>
<?php endwhile; ?>
这是我的网站网址http://www.virmodrosti.com/zdravje/ 我想要的只是第一个帖子不会显示两次,而只是移动到宽帖子设计。大帖子在内容范围内。让我知道该怎么做。谢谢。
【问题讨论】:
-
你只需要一个简单的
if声明 -
我不熟悉 WordPress 和所涉及的 PHP 方法,但似乎如果您可以尝试在您的
while循环中添加一些类似于<?php if( this_post != first_post ) : ?> [POST CONTENTS HERE] <?php endif; ?>的内容。 (换句话说,添加一个if语句,如@cmorrissey 建议的) -
尝试了很多东西,但都不管用。