dpp78272 2018-07-04 09:05
浏览 39
已采纳

使用PHP修改WordPress中的类别模板

I am having some trouble building the category template i want. Here is an example of one of my categories: http://transcorrect.bg/pi-de/category/versicherungen/

I want this field http://prntscr.com/k2d5xg to show posts only from the current category. I am attaching the code i am using right now, but it is only for specific category. What i want is to be on archive.php file as a code, that takes dynamically the category 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>

I can't figure out how to get it so if someone has made something similar i will be thankful to know how :)

  • 写回答

1条回答 默认 最新

  • doumi4676 2018-07-04 12:43
    关注

    I have worked it out. If anyone needs similar thing i am posting how i converted the code i posted earlier.

    <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); if (have_posts()) : while (have_posts()) : the_post(); ?>
    " style="color:#00315C"> " style="float:right"> [ mehr ]

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 MATLAB APP 制作出现问题
  • ¥15 wannier复现图像时berry曲率极值点与高对称点严重偏移
  • ¥15 利用决策森林为什么会出现这样·的问题(关键词-情感分析)
  • ¥15 DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI[/untitled30_war_e
  • ¥15 使用deepspeed训练,发现想要训练的参数没有梯度
  • ¥15 寻找一块做为智能割草机的驱动板(标签-stm32|关键词-m3)
  • ¥15 信息管理系统的查找和排序
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),怎么用读取的电磁传感器信号表示小车所在的位置
  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)
  • ¥15 PB中矩阵文本型数据的总计问题。