有几个人接触过它,但似乎没有人直接问过它。我试图提供一个客户的模板边栏中的链接列表的自定义应用程序。似乎很少定制链接列表元素的布局。例如,我想在图片之前显示标题,并在锚点中包装整个内容(标题、图片和描述)。
我刚刚开始使用functions.php文件,但似乎解决不了这个问题。谁有我可以用来做这件事的示例函数?
干杯,
T
发布于 2011-03-24 13:05:59
如果你是指书签列表的话?
您可以使用以下命令调用过滤器:
add_filter($this->_filter, array($this,'ReplaceAll'), 9); (in a class)
or
add_filter('some_filter', 'ReplaceAll', 9); (not in a class)
其中$this-filter是您的过滤器,例如'bookmark_list‘和'ReplaceAll’是您要编写的函数。请参阅:http://codex.wordpress.org/Plugin_API/Filter_Reference并查看“博客卷过滤器”一章,了解大多数可用的过滤器。
然后你可以像往常一样写你的函数'ReplaceAll‘。
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;
}
就该函数中的功能而言,您可以定义一个正则表达式:
const HTML_REF_REGEX2 = '/<a(.*?)href=[\'"](.*?)[\'"](.*?)>(.*?)<\\/a>/i';
然后用匹配项重新洗牌部分,例如:
return '<a' . $arrUrlMatches[1] . 'href="' . $arrUrlMatches[2]
. '"' . $arrUrlMatches[3] .'>' . 'hello world'. $arrUrlMatches[4] . '</a>';
(有关其工作原理,请参阅:http://php.net/manual/en/function.preg-match.php )
这样你就可以让它看起来像你想要的任何方式。
https://stackoverflow.com/questions/5412849
复制相似问题