如何使用walker替换核心功能
我想修改导航中列出页面的方式,特别是 wp-includes/classes.php 中的 el_start 函数。
我首先直接修改了classes.php,它工作得很好,但现在我想恢复classes.php并将修改移出wordpress的内部文件。
我写了一个我想使用的 walker 类,但我不知道如何使用它。我想将当前的调用 wp_list_pages() 替换为:
$walker_pages = new Walker_Page_CustomTitle;
wp_list_pages(array('walker' => $walker_pages, 'title_li' => '', 'depth' => '1'));
我尝试使用如下过滤器:
function wp_list_pages_custom() {
$walker_pages = new Walker_Page_CustomTitle;
wp_list_pages(array('walker' => $walker_pages, 'title_li' => '', 'depth' => '1'));
}
add_filter('widget_area_primary_aside', 'wp_list_pages_custom');
但使用此过滤器,该网站将不再加载。
教程这里说我应该放置这段代码在 header.php 中,但这只是将我的页面链接放在标签中。
我希望我说得有道理。谢谢。
I want to modify the way pages are listed in the navigation, particularly the function el_start from wp-includes/classes.php.
I've first modified the classes.php directly and it worked fine butnow I want to revert classes.php and move the modification out of wordpress' internal files.
I wrote a walker class that I want to use but I don't know how to use it. I want to replace the current call wp_list_pages() to this:
$walker_pages = new Walker_Page_CustomTitle;
wp_list_pages(array('walker' => $walker_pages, 'title_li' => '', 'depth' => '1'));
I've tried using a filter like so:
function wp_list_pages_custom() {
$walker_pages = new Walker_Page_CustomTitle;
wp_list_pages(array('walker' => $walker_pages, 'title_li' => '', 'depth' => '1'));
}
add_filter('widget_area_primary_aside', 'wp_list_pages_custom');
But with this filter, the site won't load anymore.
The tutorial here says I should put this code in header.php but that just puts my page links in the tag.
I hope I'm making sense. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
wp_list_pages()
在执行任何进一步的代码之前对传递的参数有一个过滤器,那就太理想了。然而,我能看到的最好的方法是,简单地使用
wp_list_pages()
而不传递 walker 参数,使用 your walker 是这样的;更新:
编辑了
add_filter
调用以接受两个参数。It would be ideal if
wp_list_pages()
had a filter on the passed arguments, before it executed any further code.However, the best approach I can see, whereby simply using
wp_list_pages()
without passing a walker argument uses your walker is like so;UPDATE:
Edited the
add_filter
call to accept two arguments.