【发布时间】:2018-11-07 05:59:30
【问题描述】:
我在我的 Wordpress 新闻站点中有一个 php 代码,它将在一个容器中一次显示来自 2 个类别的新闻和事件的 4 个不同的帖子。但是我当前的代码只显示了一个类别的一个帖子 4 次,尽管新闻和事件类别中有 4 个帖子。我想在容器中显示 4 个来自新闻和事件的不同帖子,而不是现在正在发生的 1 个帖子显示 4 次。 这是我的代码 sn-p:
<div class="dc-news-trend">
<?php
$args = array( 'posts_per_page' => 4, 'category' =>'50,52', 'orderby'=>'date','orer'=>'DESC');
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) :
setup_postdata( $post ); ?>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="row margin-top-1">
<div class="col-lg-4 col-md-4 col-sm-6 col-6">
<?php the_post_thumbnail('full', array( 'class' => 'img-fluid')); ?>
</div>
<div class="col-lg-8 col-md-8 col-sm-6 col-6">
<a href="<?php the_permalink(); ?>" class="dc-news-link"><?php the_title(); ?></a>
<p class="dc-news-date">
<?php echo get_the_date(); ?>
</p>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-12">
<div class="row margin-top-1">
<div class="col-lg-4 col-md-4 col-sm-6 col-6">
<?php the_post_thumbnail('full', array( 'class' => 'img-fluid')); ?>
</div>
<div class="col-lg-8 col-md-8 col-sm-6 col-6">
<a href="<?php the_permalink(); ?>" class="dc-news-link"><?php the_title(); ?></a>
<p class="dc-news-date">
<?php echo get_the_date(); ?>
</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="row margin-top-1">
<div class="col-lg-4 col-md-4 col-sm-6 col-6">
<?php the_post_thumbnail('full', array( 'class' => 'img-fluid')); ?>
</div>
<div class="col-lg-8 col-md-8 col-sm-6 col-6">
<a href="<?php the_permalink(); ?>" class="dc-news-link"><?php the_title(); ?></a>
<p class="dc-news-date">
<?php echo get_the_date(); ?>
</p>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-12">
<div class="row margin-top-1">
<div class="col-lg-4 col-md-4 col-sm-6 col-6">
<?php the_post_thumbnail('full', array( 'class' => 'img-fluid')); ?>
</div>
<div class="col-lg-8 col-md-8 col-sm-6 col-6">
<a href="<?php the_permalink(); ?>" class="dc-news-link"><?php the_title(); ?></a>
<p class="dc-news-date">
<?php echo get_the_date(); ?>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endforeach;
wp_reset_postdata();
?>
</div>
【问题讨论】: