我将wordpress与bootstrap合并,我希望得到这样的东西:
1|
| 2
3|
我检查是否有帖子(当时有3个)。接下来是循环并显示博客...但它显示空框...
我做错了什么? 或者也许有更好的方法来做到这一点?
<div class="wrapper">
<?php
$rest_query = new WP_Query(array(
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => array('post'),
'post_status' => 'publish'
));
if($rest_query->have_posts()):
?>
<?php while($rest_query->have_posts()): $rest_query->the_post(); ?>
<?php
if ($rest_query->current_post == 0)
{
echo '<div class="row">
<div class="col-md-6">
<div class="single first-post">
<a href="<?php the_permalink(); ?>"><div class="thumb"><?php the_post_thumbnail(); ?></div></a>
<div class="content">
<a href="<?php the_permalink(); ?>"><h1><?php the_title(); ?></h1></a>
<div class="data">
<p class="date"><?php echo get_the_date();s ?></p>
<p class="social">0 shares / 0 comments</p>
</div>
</div>
</div>
</div>
<div class="middleLine"></div>
<div class="col-md-6"></div>
</div>';
}
elseif ($rest_query->current_post == 1)
{ echo '<div class="row">
<div class="col-md-6"></div>
<div class="middleLine"></div>
<div class="col-md-6">
<div class="single secound-post">
<a href="<?php the_permalink(); ?>"><div class="thumb"><?php the_post_thumbnail(); ?></div></a>
<div class="content">
<a href="<?php the_permalink(); ?>"><h1><?php the_title(); ?></h1></a>
<div class="data">
<p class="date"><?php echo get_the_date();s ?></p>
<p class="social">0 shares / 0 comments</p>
</div>
</div>
</div>
</div>
</div>'; }
?>
<?php endwhile; ?>
<?php endif; ?>
</div>
答案 0 :(得分:1)
我认为您的代码在页面中显示时会出现一些错误。当你使用ECHO时,你不应该在里面使用PHP标签,这就是为什么它不能用于你的情况。
修改你的代码:
<div class="wrapper">
<?php
$rest_query = new WP_Query(array(
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => array('post'),
'post_status' => 'publish'
));
if($rest_query->have_posts()):
?>
<?php while($rest_query->have_posts()): $rest_query->the_post(); ?>
<?php
if ($rest_query->current_post == 0)
{
echo '<div class="row">
<div class="col-md-6">
<div class="single first-post">
<a href="'.the_permalink().'"><div class="thumb">'.the_post_thumbnail().'</div></a>
<div class="content">
<a href="'.the_permalink().'"><h1>'.the_title().'</h1></a>
<div class="data">
<p class="date">'.get_the_date().'</p>
<p class="social">0 shares / 0 comments</p>
</div>
</div>
</div>
</div>
<div class="middleLine"></div>
<div class="col-md-6"></div>
</div>';
}
elseif ($rest_query->current_post == 1)
{ echo '<div class="row">
<div class="col-md-6"></div>
<div class="middleLine"></div>
<div class="col-md-6">
<div class="single secound-post">
<a href="'.the_permalink().'"><div class="thumb">'.the_post_thumbnail().'</div></a>
<div class="content">
<a href="'.the_permalink().'"><h1>'.the_title().'</h1></a>
<div class="data">
<p class="date">'.get_the_date().'</p>
<p class="social">0 shares / 0 comments</p>
</div>
</div>
</div>
</div>
</div>'; }
?>
<?php endwhile; ?>
<?php endif; ?>
注意:如果你想打印任何PHP变量,那么应该使用它,因为我已经显示了上面的代码。
感谢你