【发布时间】:2020-04-20 04:44:21
【问题描述】:
我目前正在开发一个 WordPress 期刊主题,我想知道最好的方法
1. 根据卷数和问题(例如,第 1 卷第 1 卷、第 1 卷第 2 卷或第 1 卷第 3 卷)对文章(自定义帖子类型)进行排序。
2. 在首页显示当前期(如第一卷第三期)
到目前为止我做了什么
1. 我使用链接在一起的 ACF 创建了一个自定义分类(卷和问题)和一个自定义字段类型(分类)。使用下面的代码,我能够显示分类中的所有帖子,无论它们是在第 1 卷第 1 卷、第 1 卷第 2 卷还是第 1 卷第 3 卷中。
<?php
$homepageArticles = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'article',
'meta_key' => 'current_issue',
'orderby' => 'meta_value',
));
while($homepageArticles->have_posts()){
$homepageArticles->the_post(); ?>
<div class="j-header shadow">
<div class= "j-category"> <?php the_field('article_category'); ?>
</div>
<div class="j-section">
<div class="j-article-thumbnail ">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium'); ?></a>
</div>
<div class="j-article-excerpts jp-excerpt ">
<div class="j-title">
<h1 class='j-title'><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h1>
</div>
<div class="j-authors"> <span>By: </span>
<?php the_field('authors'); ?></div>
<div id="mini-navbar">
<ul class="mini-navbar">
<li><a href="#">Abstract</a></li>
<li><a href="<?php the_permalink(); ?>">HTML Full Text</a></li>
<li><a href="<?php the_field('uplaod_pdf'); ?>">PDF</a></li>
</ul>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
<?php
} wp_reset_postdata();
?>
-
我还尝试使用第二个代码使用 meta_query 过滤帖子,但是当我需要比较我创建的变量时我感到困惑`
$currentIssue = get_field('current_issue'); $pastIssue = get_field('current_issue');$homepageArticles = new WP_Query(array( 'posts_per_page' => -1, 'post_type' => '文章', 'meta_key' => 'current_issue', 'orderby' => 'meta_value', 'meta_query' => 数组( 大批( 'key' => $currentIssue, '比较' => '>', '价值' => $pastIssue )
))); while($homepageArticles->have_posts()){ $homepageArticles->the_post(); ?> <div class="j-header shadow"> <div class= "j-category"> <?php the_field('article_category'); ?> </div> <div class="j-section"> <div class="j-article-thumbnail "> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium'); ?></a> </div> <div class="j-article-excerpts jp-excerpt "> <div class="j-title"> <h1 class='j-title'><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></h1> </div> <div class="j-authors"> <span>By: </span> <?php the_field('authors'); ?></div> <div id="mini-navbar"> <ul class="mini-navbar"> <li><a href="#">Abstract</a></li> <li><a href="<?php the_permalink(); ?>">HTML Full Text</a></li> <li><a href="<?php the_field('uplaod_pdf'); ?>">PDF</a></li> </ul> </div> </div> </div> <div class="clearfix"></div> </div>`
我也想知道是否有更好的方法来对 WordPress 中基于卷和问题的文章进行排序
【问题讨论】:
标签: wordpress wordpress-theming custom-wordpress-pages