add_filter('wp_list_categories', 'myCatNoBrk', 10, 1);
function myCatNoBrk($OrgCat) {
$CatNoBrk = preg_replace('/<br \/>/',',',$OrgCat);
return $CatNoBrk;
}
Hello, this is part of a wordpress function that would replace html breaks with commas. How could I alter this to also remove and add 'x' around each element?
in oth开发者_如何学Goer words: The output code is something like
<a href="xxx">cat1</a><br>
<a href="xxx2">cat2</a><br>
and so on
I'd like to change this to show only ('cat1','cat2') for an array definition
example output:
<?php $grades_array = array('a+','a','a-','b+','b','b-','c+');?>
I am not 100% sure what you are trying to achieve, but here's a replacement function that lets you specify what you are putting in place of the break tags (<br />)
add_filter('wp_list_categories', 'myCatNoBrk', 10, 1);
function myCatNoBrk($OrgCat,$replacement = ',') {
$CatNoBrk = preg_replace('/<br \/>/',$replacement,$OrgCat);
return $CatNoBrk;
}
UPDATE: try this
add_filter('wp_list_categories', 'myCatNoBrk', 10, 1);
function myCatNoBrk($OrgCat,) {
preg_match_all(' /(?<=^|>)[^><]+?(?=<|$)/',$OrgCat,$CatNoBrk,PREG_PATTERN_ORDER);
return '(\''.implode('\',\'',$CatNoBrk).'\')';
}
精彩评论