{"id":94,"date":"2014-05-29T12:43:59","date_gmt":"2014-05-29T12:43:59","guid":{"rendered":"http:\/\/localhost\/__sites\/3d_blog\/?p=94"},"modified":"2014-06-07T11:05:43","modified_gmt":"2014-06-07T11:05:43","slug":"category-count-with-style","status":"publish","type":"post","link":"https:\/\/blog.silverterra.net\/?p=94","title":{"rendered":"category count with style"},"content":{"rendered":"<blockquote><p>Goal: fix the categories list<\/p><\/blockquote>\n<p>Get the Categories list:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">\r\nwp_list_categories('sort_column=name&amp;optioncount=1&amp;hierarchical=0&amp;title_li=&lt;h2&gt;Categories&lt;\/h2&gt;&amp;show_count=1');\r\n<\/pre>\n<p>The result is not too correct. The count is out of my style.<\/p>\n<pre data-enlighter-language=\"html\" class=\"EnlighterJSRAW\">\r\n&lt;ul&gt;\t\r\n  &lt;li class=&quot;...&quot;&gt;&lt;a href=&quot;..&quot; title=&quot;...&quot;&gt;javascript&lt;\/a&gt; (7)&lt;\/li&gt;\r\n  &lt;li class=&quot;...&quot;&gt;&lt;a href=&quot;..&quot; title=&quot;...&quot;&gt;oracle&lt;\/a&gt; (1)&lt;\/li&gt;\r\n  &lt;li class=&quot;...&quot;&gt;&lt;a href=&quot;..&quot; title=&quot;...&quot;&gt;web trick&lt;\/a&gt; (1)&lt;\/li&gt;\r\n  &lt;li class=&quot;...&quot;&gt;&lt;a href=&quot;..&quot; title=&quot;...&quot;&gt;wordpress&lt;\/a&gt; (6)&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n<\/pre>\n<p>To correct this I will wrap the count into a span and I can stylise that after.<br \/>\nAdd a new filter to the category list creator. Insert this code to the end of the <strong>functions.php<\/strong> file.<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">\r\nadd_filter('wp_list_categories', 'cat_count_span');\r\nfunction cat_count_span($links) {\r\n  $links = str_replace('&lt;\/a&gt; (', '&lt;\/a&gt; &lt;span&gt;(', $links);\r\n  $links = str_replace(')', ')&lt;\/span&gt;', $links);\r\n  return $links;\r\n}\r\n<\/pre>\n<p>For the correct functioning we need to check the <strong>wp-setting.php<\/strong> file. In the <em>Load early WordPress files<\/em> section be sure the plugin.php is the first like here:<\/p>\n<pre data-enlighter-language=\"php\" class=\"EnlighterJSRAW\">\r\n...\r\n\/\/ Load early WordPress files.\r\nrequire( ABSPATH . WPINC . '\/plugin.php' );\r\nrequire( ABSPATH . WPINC . '\/functions.php' );\r\n...\r\n<\/pre>\n<p>the result is:<\/p>\n<pre data-enlighter-language=\"html\" class=\"EnlighterJSRAW\">\r\n&lt;ul&gt;\t\r\n  &lt;li class=&quot;...&quot;&gt;&lt;a href=&quot;..&quot; title=&quot;...&quot;&gt;javascript&lt;\/a&gt; &lt;span&gt;(7)&lt;\/span&gt;&lt;\/li&gt;\r\n  &lt;li class=&quot;...&quot;&gt;&lt;a href=&quot;..&quot; title=&quot;...&quot;&gt;oracle&lt;\/a&gt; &lt;span&gt;(1)&lt;\/span&gt;&lt;\/li&gt;\r\n  &lt;li class=&quot;...&quot;&gt;&lt;a href=&quot;..&quot; title=&quot;...&quot;&gt;web trick&lt;\/a&gt; &lt;span&gt;(1)&lt;\/span&gt;&lt;\/li&gt;\r\n  &lt;li class=&quot;...&quot;&gt;&lt;a href=&quot;..&quot; title=&quot;...&quot;&gt;wordpress&lt;\/a&gt; &lt;span&gt;(6)&lt;\/span&gt;&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n<\/pre>\n<p>I can use a style now to fix the problem.<\/p>\n<blockquote><p>sources: <a href=\"http:\/\/wordpress.stackexchange.com\/questions\/17324\/wrap-post-count-in-a-span\" title=\"correction\" target=\"_blank\">correction<\/a>, <a href=\"http:\/\/wordpress.org\/support\/topic\/fatal-error-call-to-undefined-function-add_filter\" title=\"fix filter error\" target=\"_blank\">fix filter error<\/a><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Goal: fix the categories list Get the Categories list: The result is not too correct. The count is out of my style. To correct this I will wrap the count into a span and I can stylise that after. Add a new filter to the category list creator. Insert this code to the end of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=94"}],"version-history":[{"count":16,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions\/450"}],"wp:attachment":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}