我在页面中创建了一个类别列表。代码如下:
<?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>';
}
?>
但结果却不行。任何人都可以帮助我,代码的哪一部分应该修复。
答案 0 :(得分:1)
使用/*
* initPQExpBuffer
*
* Initialize a PQExpBufferData struct (with previously undefined contents)
* to describe an empty string.
*/
void
initPQExpBuffer(PQExpBuffer str)
{
str->data = (char *) malloc(INITIAL_EXPBUFFER_SIZE);
if (str->data == NULL)
{
str->data = (char *) oom_buffer; /* see comment above */
str->maxlen = 0;
str->len = 0;
}
else
{
str->maxlen = INITIAL_EXPBUFFER_SIZE;
str->len = 0;
str->data[0] = '\0';
}
}
而非get_tags()
。
应该修复哪部分代码
(1)替换它:
get_the_tags()
..用这个:
$tags = get_the_tags( $args );
(2)替换它:
$tags = get_tags( $args );
..用这个:
$tag->tag_count