使用 PHP 修改 WordPress 中的类别模板
Modification of category template in WordPress using PHP
我在构建我想要的类别模板时遇到了一些问题。这是我的其中一个类别的示例:http://transcorrect.bg/pi-de/category/versicherungen/
我希望此字段 http://prntscr.com/k2d5xg 仅显示来自当前类别的帖子。我附上了我现在正在使用的代码,但它仅适用于特定类别。我想要的是作为代码放在 archive.php 文件中,动态获取类别 ID。
Minimal example of code
<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>
我不知道如何得到它所以如果有人做了类似的东西我会很感激知道如何:)
我已经解决了。
如果有人需要类似的东西,我会发布我如何转换我之前发布的代码。
<div class="row">
<div class="headline-box" style="margin-bottom:10px;">Weitere Artikel</div>
<?php $current_cat_id = get_query_var('cat'); $showposts = 10;
$args = array('cat' => $current_cat_id, 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => $showposts,'post_status' => 'publish');
query_posts($args);
如果(have_posts()):而(have_posts()):the_post(); ?>
" 样式="color:#00315C">
" style="float:right"> [更多]
<?php endwhile; ?>
<?php endif; ?>
我在构建我想要的类别模板时遇到了一些问题。这是我的其中一个类别的示例:http://transcorrect.bg/pi-de/category/versicherungen/
我希望此字段 http://prntscr.com/k2d5xg 仅显示来自当前类别的帖子。我附上了我现在正在使用的代码,但它仅适用于特定类别。我想要的是作为代码放在 archive.php 文件中,动态获取类别 ID。
Minimal example of code
<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>
我不知道如何得到它所以如果有人做了类似的东西我会很感激知道如何:)
我已经解决了。 如果有人需要类似的东西,我会发布我如何转换我之前发布的代码。
<div class="row">
<div class="headline-box" style="margin-bottom:10px;">Weitere Artikel</div>
<?php $current_cat_id = get_query_var('cat'); $showposts = 10;
$args = array('cat' => $current_cat_id, 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => $showposts,'post_status' => 'publish');
query_posts($args);
如果(have_posts()):而(have_posts()):the_post(); ?>
" 样式="color:#00315C">
" style="float:right"> [更多]
<?php endwhile; ?>
<?php endif; ?>