【发布时间】:2018-07-04 09:05:39
【问题描述】:
我在构建我想要的类别模板时遇到了一些问题。这是我的一个类别的示例:http://transcorrect.bg/pi-de/category/versicherungen/
我希望此字段 http://prntscr.com/k2d5xg 仅显示来自当前类别的帖子。我附上了我现在正在使用的代码,但它仅适用于特定类别。我想要的是将archive.php文件作为代码,动态获取类别ID。
代码的最小示例
<div class="row">
<div class="headline-box" style="margin-bottom:10px;">Weitere Artikel</div>
<?php
// get the top-category posts
$the_query = new WP_Query(array(
'category_name' => 'Versicherungen',
'posts_per_page' => 10,
));
if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div id="list-news-home" class="col-lg-12" style="padding-top:10px;padding-bottom:10px;">
<img src="http://transcorrect.bg/pi-de/wp-content/uploads/2018/07/arrow1.png" style="padding-right:20px;"><a href="<?php echo get_permalink(); ?>" style="color:#00315C"><?php the_title(); ?></a>
<a href="<?php echo get_permalink(); ?>" style="float:right"> [ mehr ] </a>
</div>
<hr style="margin-top:50px;margin-bottom:10px">
<?php endwhile; ?>
<?php endif; ?>
</div>
我不知道如何得到它,所以如果有人做了类似的东西,我会很感激知道如何:)
【问题讨论】:
-
欢迎来到 Stack Overflow!请edit您的问题包括minimal reproducible example。请阅读该链接并确保您在问题中发布的代码是最少(仅是重现所需的最少代码),完整(所有必要的代码重现)和可验证(我们可以仅使用您问题中的代码重现该问题)。这将通过澄清问题来帮助 Stack Overflow 社区。span>
标签: php wordpress categories