【问题标题】:Modification of category template in WordPress using PHP使用 PHP 修改 WordPress 中的类别模板
【发布时间】: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


【解决方案1】:

我已经解决了。 如果有人需要类似的东西,我将发布我如何转换我之前发布的代码。

<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' ); 查询帖子($args); if (have_posts()) : 而 (have_posts()) : the_post(); ?>
" 样式="颜色:#00315C"> " style="float:right"> [ mehr ]

        <?php endwhile; ?>
    <?php endif; ?>  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多