【问题标题】:add hash to wordpress wp_listcategories将哈希添加到 wordpress wp_listcategories
【发布时间】:2011-06-08 11:11:38
【问题描述】:

是否可以将#附加到

wp_list_categories( 'include=13&title_li=&style=none&echo=0')?

在最终链接类别中,链接需要如下所示:domain/categories/somepost#

【问题讨论】:

  • 您可以复制 WP 的函数(wp-includes/category-template.php,第 417 行)并添加哈希,或者在 DOMReady 上使用 JS 附加它。
  • @konzepz 不明白在哪里复制 wp 功能?

标签: php wordpress hash categories


【解决方案1】:

为 wp_list_categories 的输出添加过滤器可以在 php.ini 中执行此操作。 您需要使用 preg_replace 和正则表达式来查找网址。 例如:

add_filter('wp_list_categories', 'filter_categories', 10, 2);

将您的“filter_categories”函数添加到过滤器 - 不要将其称为过滤器类别,将其称为独特的东西,例如 sjn_filter_categories。

function filter_categories($output, $args=array()){
      return preg_replace('/(\<a\shref=\"?[^\>]+?)\"/', '$1#"', $output);
}

将获取输出,在其中搜索 href url,删除 '"' 并重新添加 '#' 和 '"'。 我希望这会有所帮助!

【讨论】:

  • 对我来说看起来很复杂:-(我很乐意帮助我
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-03
  • 1970-01-01
  • 2020-12-08
  • 2011-07-28
  • 2016-09-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多