现在,从http://codex.wordpress.org/Template_Tags/wp_list_categories 我们可以使用以下代码在wordpress页面中列出类别:
<?php
$args = array(
\'show_option_all\' => \'\',
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'style\' => \'list\',
\'show_count\' => 0,
\'hide_empty\' => 1,
\'use_desc_for_title\' => 1,
\'child_of\' => 0,
\'feed\' => \'\',
\'feed_type\' => \'\',
\'feed_image\' => \'\',
\'exclude\' => \'\',
\'exclude_tree\' => \'\',
\'include\' => \'\',
\'hierarchical\' => 1,
\'title_li\' => __( \'Categories\' ),
\'show_option_none\' => __( \'No categories\' ),
\'number\' => null,
\'echo\' => 1,
\'depth\' => 0,
\'current_category\' => 0,
\'pad_counts\' => 0,
\'taxonomy\' => \'category\',
\'walker\' => null
);
wp_list_categories( $args );
?>
并根据需要更改其选项。然而,这将始终与
<li><a>something</a></li>
标签我想更改此代码,例如,我想
<a>
外部标签
<li>
. 我怎样才能做到这一点?
最合适的回答,由SO网友:TTech IT Solutions 整理而成
<ul>
<?php
$categories = get_categories();
foreach($categories as $category)
{
?>
<li><a href="<?php echo get_category_link($category->cat_id);?>">$category->name</a></li>
<?php
}
?>
</ul>
只要简单地更改foreach循环中的内容,就可以输出您想要的内容。如果在多个位置执行此操作,请将其放入函数中,并从函数文件中回显该函数。
将其放入您的函数中。php
<?php
function outputcategories()
{
?>
<ul>
<?php
$categories = get_categories();
foreach($categories as $category)
{
?>
<li><a href="<?php echo get_category_link($category->id);?>">$category->name</a></li>
<?php
}
?>
</ul>
<?php
}
然后要使用它,请运行以下命令
<?php echo outputcategories(); ?>