我在iframe中打开我的帖子get_the_category_list
列出帖子的类别。问题是,当用户单击类别链接时,它会在iframe中打开。如何将这些生成的链接的目标设置为“\\u parent”?
在父窗口中打开The_Category_List
1 个回复
最合适的回答,由SO网友:chrisguitarguy 整理而成
get_the_category_list
通过过滤器运行it输出the_category
. 你可以在那里挂上钩,想换什么就换什么。像这样的方法应该有效(未经测试):
<?php
add_filter(\'the_category\', \'wpse90955_the_category\');
function wpse90955_the_category($cat_list)
{
return str_ireplace(\'<a\', \'<a target="_parent"\', $cat_list);
}
如果您只需要在某些位置使用列表过滤器,您可以在插件或主题的functions.php
, 然后添加过滤器,调用get_the_category_list
, 然后拆下滤清器。<?php
// assume wpse90955_the_category was defined elsewhere and is already loaded
add_filter(\'the_category\', \'wpse90955_the_category\');
echo get_the_category_list($some_sep, $parents, $some_post_id);
remove_filter(\'the_category\', \'wpse90955_the_category\');
结束