首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WP Rig -如何按类别过滤帖子

WP Rig -如何按类别过滤帖子
EN

Stack Overflow用户
提问于 2020-08-19 05:27:04
回答 1查看 26关注 0票数 0

在WP Rig系统中,我创建了一个自定义内容模板,以便让一些页面显示来自特定类别的帖子。我在过去成功地做了很多次,但我使用的编码在可湿性粉剂钻机系统中不起作用。下面是我使用的代码:

代码语言:javascript
复制
<?php $the_query = new WP_Query( 'posts_per_page=12', '&category_name=reviews'); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <a href="<?php the_permalink() ?>"><?php the_post_thumbnail();?></a> <h3 class="home-post-title"><?php the_title(); ?></h3> <p><?php the_excerpt(); ?></p>

这会在WP Rig系统中创建错误。以下是在可湿性粉剂钻机工作的代码:

代码语言:javascript
复制
<article id="post-<?php the_ID(); ?>" <?php post_class( 'entry' ); ?>> <?php get_template_part( 'template-parts/content/entry_header', get_post_type() ); if ( is_search() ) { get_template_part( 'template-parts/content/entry_summary', get_post_type() ); } else { get_template_part( 'template-parts/content/entry_content', get_post_type() ); } get_template_part( 'template-parts/content/entry_footer', get_post_type() ); ?> </article><!-- #post-<?php the_ID(); ?> --> 

我只需要以某种方式过滤这个类别,并将帖子限制在12个。

EN

回答 1

Stack Overflow用户

发布于 2020-08-21 21:42:31

这就是答案--在GitHub上找到的:

因为WP_Query是一个类,所以需要在模板中包含"use WP_Query;“。所以现在你的front-page.php应该看起来像这样:

代码语言:javascript
复制
<?php
/**
 * Render your site front page, whether the front page displays the blog posts index or a static page.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#front-page-display
 *
 * @package wp_rig
 */

namespace WP_Rig\WP_Rig;
use WP_Query;

get_header();

etc....
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63476860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档