A few people have touched on it, but no-one appears to have outright asked it. I'm trying to provide custom application of the link list in the sidebar of a template for a client. There seems to be very little customisation of the layout of the link list element. For instance, I'd like to show the title before the image and wrap the whole lot (title, image and description) in the anchor.
I've just开发者_JAVA技巧 started playing with the functions.php file, but can't seem to work this one out. Anyone have a sample function I could use for this?
Cheers,
T
If you mean the bookmark list?
You call into the filter with e.g.:
add_filter($this->_filter, array($this,'ReplaceAll'), 9); (in a class)
or
add_filter('some_filter', 'ReplaceAll', 9); (not in a class)
Where $this-filter is your filter e.g. 'bookmark_list' and 'ReplaceAll' is the function you will write. See: http://codex.wordpress.org/Plugin_API/Filter_Reference and check the chapter "blogroll filters" for most available filters.
you can then write your function 'ReplaceAll' like usual e.g.
function ReplaceAll($something_that_comes_in_from_the_filter)
{
// do stuff e.g. $something_that_comes_in_from_the_filter =
$something_that_comes_in_from_the_filter . ' hello world';
return $something_that_comes_in_from_the_filter;
}
In terms of functionality inside that function you can define e.g. a regular expression:
const HTML_REF_REGEX2 = '/<a(.*?)href=[\'"](.*?)[\'"](.*?)>(.*?)<\\/a>/i';
and then reshuffle the parts with the matches e.g.:
return '<a' . $arrUrlMatches[1] . 'href="' . $arrUrlMatches[2]
. '"' . $arrUrlMatches[3] .'>' . 'hello world'. $arrUrlMatches[4] . '</a>';
(See: http://php.net/manual/en/function.preg-match.php for how that works)
So in that way you can make it look any way you want.
精彩评论