在<a> Tag Itself

时间:2015-10-13 14:24:13

标签: wordpress

As you probably know, to get the category list in WordPress, you use:

<ul>
<?php wp_list_categories('orderby=name&show_count=1&title_li='); ?>
</ul>

Is it possible to get it without <li>, and display link counts of each category inside the <a> tag itself?

For example, I want to use this structure for categories:

<nav>
    <a href="?cat=1">Arabesque (3)</a>
    <a href="?cat=2">Business (5)</a>
</nav>

instead of this typical one:

<nav>
<ul>
    <li><a href="?cat=1">Arabesque</a> (3)</li>
    <li><a href="?cat=2">Business</a> (5)</li>
</ul>
</nav>

3 个答案:

答案 0 :(得分:2)

最好的方法是使用过滤器:

add_filter( 'wp_list_categories', 'mytheme_category_list' );
function mytheme_category_list( $list ) {
    //remove ul tags
    $list = str_replace( '<ul>', '', $list );
    $list = str_replace( '</ul>', '', $list );
    //remove li tags
    $list = preg_replace( '~<li(.*?)>~s', '', $list );
    $list = str_replace( '</li>', '', $list );
    //move count inside a tags
    $list = str_replace( '</a> (', '(', $list );
    $list = str_replace( ')', ')</a>', $list );
    return $list;
}

答案 1 :(得分:0)

要在package com.badlogic.drop; import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; public class AndroidLauncher extends AndroidApplication { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config= new AndroidApplicationConfiguration(); config.useAccelerometer = false; config.useCompass = false; initialize(new Drop(), config); } } 标记内移动帖子计数,请在functions.php文件中使用此代码段:

a

来源:https://gist.github.com/blainerobison/1f1e59c99f5c9a78b93d

答案 2 :(得分:0)

从GitHub https://gist.github.com/blainerobison/1f1e59c99f5c9a78b93d

获得它

完美工作

/ **  *在链接内移动类别发布计数  *  *过滤器wp_list_categories()  *  * @param字符串$ links链接html输出  * @返回字符串  * / 函数prefix_move_category_count($ links){

$links = str_replace( '</a> <span class="count">', ' <span class="count">', $links );
$links = str_replace( '</span>', '</span></a>', $links );

return $links;

} add_filter('wp_list_categories','prefix_move_category_count');

/ **  *在链接内部移动存档发布数  *  *过滤器get_archives_link()  *  * @param字符串$ links链接html输出  * @返回字符串  * / 函数prefix_move_archive_count($ links){

$links = str_replace( '</a>&nbsp;(', ' <span class="count">(', $links );
$links = str_replace( ')', ')</span></a>', $links );

return $links;

} add_filter('get_archives_link','prefix_move_archive_count');