我正在尝试创建自己的简单侧栏,以显示以下内容:
browse by archives (monthly) - it works
brows by categories (only main, no subcategories) does not work, misisng ref link.
browse by tag (all tags with links). does not work. Could someone look at the code and let me know what i do wrong.
我尝试对以上所有内容使用相同的选择选项下拉结构。代码如下。谢谢你的帮助
<div class="tag-archive" style="margin: 20px 0;">
<select class="" name="archive-dropdown" onchange="document.location.href = this.options[this.selectedIndex].value;">
<option value=""><?php echo esc_attr(__(\'Wybierz Miesiąc\')); ?></option>
<?php wp_get_archives(array(\'type\' => \'monthly\', \'format\' => \'option\', \'show_post_count\' => 1)); ?>
</select>
</div>
<div class="tag-category" style="margin: 20px 0;">
<?php
echo \'<select name="categories">\';
// Add custom option as default
echo \'<option>\' . __(\'Select categories\', \'text-domain\') . \'</option>\';
// Get categories as array
$args = array(
\'hide_empty\' => 0,
\'taxonomy\' => \'category\',
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'show_count\' => true,
\'hierarchical\' => true
);
$categories = get_categories($args);
foreach ($categories as $category) :
// Check if current term ID is equal to term ID stored in database
$selected = ( $stored_category_id == $category->term_id ) ? \'selected\' : \'\';
echo \'<option value="\' . $category->term_id . \'" \' . $selected . \'>\' . $category->name . \'</option>\';
endforeach;
echo \'</select>\';
?>
<div class="tag-cloud" style="margin: 20px 0;">
<?php
echo \'<select class="tags">\';
// Add custom option as default
echo \'<option>\' . __(\'Select Tag\', \'text-domain\') . \'</option>\';
// Get categories as array
$tags = get_tags(array(\'orderby\' => \'count\', \'order\' => \'DESC\'));
foreach ((array) $tags as $tag){
// Check if current term ID is equal to term ID stored in database
$selected = ($tag == $tag->term_id ) ? \'selected\' : \'\';
echo \'<option value="<a href="\' . get_tag_link ($tag->term_id) . \'" rel = "tag">\' . $tag->name . \'(\' . $tag->count . \')\'.\'</option>\';
}
echo \'</select>\';
?>
</div>