如何在包含图像和计数帖子的页面中创建列表标签

问题描述 投票:0回答:1

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

<?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个回答
1
投票

使用get_tags()而不是get_the_tags()

代码的哪一部分应该修复

(1)替换这个:

$tags = get_the_tags( $args );

..有了这个:

$tags = get_tags( $args );

(2)替换这个:

$tag->tag_count

..有了这个:

$tag->count
© www.soinside.com 2019 - 2024. All rights reserved.