我正在制作一个WordPress主题。我制作了如下所示的网格结构,
它包含两行,每行有三列。我想在此网格中显示我的WordPress数据库中的随机帖子。
这是我的代码
<div class="row">
<div class="col-xs-12">
<div class="rst-mediagrid">
<div class="div">
<?php
$args = array(
'posts_per_page' => 6,
'offset' => 0,
'category' => '2',
'category_name' => '',
'orderby' => 'date',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
global $post;
$post = get_post($args);
$next_post = get_adjacent_post( true, '', false, 'taxonomy_slug' );
?>
<div class="rst-col rst-col-50">
<div class="rst-postpic">
<?php echo get_the_post_thumbnail($post->ID); //latest post thumbnail ?>
</div>
</div>
<?php //endif; ?>
<div class="rst-col rst-col-25">
<div class="rst-postpic rst-postvideo">
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class="rst-col rst-col-25">
<div class="rst-postpic">
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class="clear"></div>
</div>
<div class="div">
<div class="rst-col rst-col-25">
<div class="rst-postpic">
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class="rst-col rst-col-25">
<div class="rst-postpic rst-postvideo">
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class="rst-col rst-col-50">
<div class="rst-postpic">
<?php echo get_the_post_thumbnail($next_post->ID); ?>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
上面的代码重复了我要以完美的顺序显示缩略图的相同图像,例如第一行有三列,第一列有最新图像第二列有前一个帖子的图像,第三列有图像之前的平均值第3篇帖子来自最新帖子和第2行也有相同的内容。
如果你有更好的建议,请告诉我。
答案 0 :(得分:1)
使用它不需要使用当前帖子的id作为参数。
<?php echo get_next_post(); ?>
答案 1 :(得分:0)
最后我找到了我的问题的解决方案,如果其他人有相同的问题,那么使用这个
@Override
public List<User> searchUsers(String criteria, Car car) {
//TODO: check params and return values based on test cases
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<User> query = builder.createQuery(User.class);
Root<User> r = query.from(User.class);
Predicate predicate = builder.conjunction();
predicate = builder.or(predicate, builder.like(r.get("username"), "%" + criteria + "%"));
predicate = builder.or(predicate, builder.like(r.get("firstName"), "%" + criteria + "%"));
predicate = builder.or(predicate, builder.like(r.get("lastName"), "%" + criteria + "%"));
predicate = builder.or(predicate, builder.like(r.get("nickname"), "%" + criteria + "%"));
// how to implement the filter by foreign key value with AND? - can be a sub query to, which will be executed first time
// I need to use 1 Predicate, not a Predicate Array!
query.select(r).where(predicate);
List<User> result = entityManager.createQuery(query).getResultList();
如果有人有更好的建议,请在这里回答你的问题以及我的代码中的任何逻辑问题然后告诉我