【发布时间】:2018-09-05 00:10:49
【问题描述】:
这可能是一个愚蠢的问题,但我就是想不通。我正在开发通过转换 html 网站创建的自定义 WordPress 主题。但是当我使用 WP_Query 时,它不会加载我的博客文章。是的,它会按循环显示博客文章列表,但是当我单击每个标题或文章的“阅读更多”链接时,它只会将地址栏中的 url 更改为文章的链接,并且然后简单地刷新希望页面。打不开,真的好累。这是我的 index.php 中的查询循环
<?php
$categories = get_categories();
foreach ( $categories as $category ) {
//define args for query
$args = array(
'cat' => $category->term_id,
'post_type' => 'post',
'posts_per_page' => '30',
);
//The main query
$query = new WP_Query( $args );
if ( $query->have_posts() ) { ?>
<section class="<?php echo $category->name; ?> listing">
<h2>Latest in <?php echo $category->name; ?>:</h2>
<?php while ( $query->have_posts() ) {
$query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'category-listing' ); ?>>
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</a>
<?php } ?>
<h3 class="entry-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php the_excerpt(); ?>
</article>
<?php } // end while ?>
</section>
<?php } // end if
// Use reset to restore original query.
wp_reset_postdata();
}
?>
</div><!-- blog-main-content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
请问我该怎么办
【问题讨论】:
-
您的主题中有
single.php文件可用作帖子的模板吗?您在哪个文件中有此代码? -
不,代码在我的 index.php 中。我还没有帖子的模板文件。我必须创建一个吗?
标签: wordpress