在WP Rig系统中,我创建了一个自定义内容模板,以便让一些页面显示来自特定类别的帖子。我在过去成功地做了很多次,但我使用的编码在可湿性粉剂钻机系统中不起作用。下面是我使用的代码:
<?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系统中创建错误。以下是在可湿性粉剂钻机工作的代码:
<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个。
发布于 2020-08-21 21:42:31
这就是答案--在GitHub上找到的:
因为WP_Query是一个类,所以需要在模板中包含"use WP_Query;“。所以现在你的front-page.php应该看起来像这样:
<?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....https://stackoverflow.com/questions/63476860
复制相似问题