【问题标题】:How create list tags in a page with image and count post如何在带有图像和计数帖子的页面中创建列表标签
【发布时间】:2018-03-02 08:03:18
【问题描述】:

我在页面中创建了一个类别列表。代码如下:

<?php
$args = array(
  'orderby' => 'name',
  'parent' => 0
  );
$categories = get_categories( $args );
foreach ( $categories as $category ) {
    echo '<div style="margin:0 0 10px 10px; border: 1px solid #888; float: left; padding:1px; text-align:center;"><a href="' . get_category_link( $category->term_id ) . '"><img src="https://arsipkoran.ga/img/logo/koran-thumb/thumb-' . $category->cat_name . '.png" alt="' . $category->cat_name . '" style="width:180px;height:30px;" /><br/>' . $category->name . '</a><br/> (' . $category->category_count . ' arsip)</div>';
}
?>

结果如以下链接一样成功:https://pustakakoran.com/direktori-e-koran/

然后我尝试应用到标签上,代码如下:

<?php
$args = array(
  'orderby' => 'name',
  'parent' => 0
  );
$tags = get_the_tags( $args );
foreach ( $tags as $tag ) {
    echo '<div style="margin:0 0 10px 10px; border: 1px solid #888; float: left; padding:1px; text-align:center;"><a href="' . get_tag_link($tag->term_id) . '"><img src="https://arsipkoran.ga/img/logo/koran-thumb/thumb-' . $tag->name . '.png" alt="' . $tag->name . '" style="width:180px;height:30px;" /><br/>' . $tag->name . '</a><br/> (' . $tag->tag_count . ' kitab)</div>';
}
?>

但是结果不行。谁能帮帮我,应该修复哪部分代码。

【问题讨论】:

    标签: wordpress tags


    【解决方案1】:

    使用get_tags() 而不是get_the_tags()。

    代码的哪一部分应该被修复

    (1) 替换这个:

    $tags = get_the_tags( $args );
    

    ..用这个:

    $tags = get_tags( $args );
    

    (2) 替换这个:

    $tag->tag_count
    

    ..用这个:

    $tag->count
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    相关资源
    最近更新 更多