我正在使用Wordpress中的wp_get_archives
函数。
<?php $args = array(
'type' => 'monthly',
'limit' => '',
'format' => 'html',
'before' => '',
'after' => '',
'show_post_count' => false,
'echo' => 1,
'order' => 'DESC'
); ?>
<?php wp_get_archives( $args ); ?>
但我希望能够更改URL -而不是将其转到我的Wordpress安装目录,我如何将其更改为我自己的自定义URL?
PS:我在从line 937
开始的general-template.php
文件中找到了这个函数的开始位置。
发布于 2014-03-24 05:46:39
我看到,在函数wp_get_archives
中,链接是使用函数get_archives_link()
构建的。在那里,我们找到了过滤器钩子get_archives_link
,它返回档案的每个超文本标记语言链接。
所以,我们可以操作这些字符串中的每一个并替换:
add_filter( 'get_archives_link', function( $html )
{
if( is_admin() ) // Just in case, don't run on admin side
return $html;
// $html is '<li><a href='http://example.com/hello-world'>Hello world!</a></li>'
$html = str_replace( 'href="http://example.com', 'href="http://example.org', $html );
return $html;
});
发布于 2014-06-11 04:18:26
brasofilo的解决方案在我身上起作用了,只做了一些小调整。
之前:
$html = str_replace( 'href="http://example.com', 'href="http://example.org', $html );
之后:
$html = str_replace( 'http://example.com', 'http://example.com/the_events', $html );
https://stackoverflow.com/questions/21387045
复制相似问题