【发布时间】:2014-10-19 21:20:40
【问题描述】:
我真的是 Wordpress 和 php 的新手。我为我的网站创建了一个主题如下:
我认为我的问题很明确:在 wordpress 管理页面中,我有四个类别:1、2、3、4。我希望类别 1 中的最后 2 个帖子显示在部分 (div) 1 中(如上所示),类别 2 中的最后 2 个帖子显示在部分 (div) 2 中,依此类推。
正如我所说,我是新手,我在 Wordpress 文档中遇到了大量的功能。
例如,我在第 2 节的 index.php(我的自定义主题)中使用了以下代码,该代码输出:“抱歉,没有符合您的条件的帖子。”
<?php
$args = array( 'post' => 'post', 'posts_per_page' => 1,'category_name'=>'تازه ها');
$the_query = new WP_Query( $args );
?>
<?php
if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif;
?>
请提供一段代码来执行此操作。
【问题讨论】:
-
我在帖子中将标签更改为类别并更改了代码,但仍然失败,尽管一切似乎都很好