首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更改wordpress wp_get_archives函数的URL

更改wordpress wp_get_archives函数的URL
EN

Stack Overflow用户
提问于 2014-01-28 01:06:23
回答 2查看 1.9K关注 0票数 2

我正在使用Wordpress中的wp_get_archives函数。

代码语言:javascript
运行
复制
<?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文件中找到了这个函数的开始位置。

EN

回答 2

Stack Overflow用户

发布于 2014-03-24 05:46:39

我看到,在函数wp_get_archives中,链接是使用函数get_archives_link()构建的。在那里,我们找到了过滤器钩子get_archives_link,它返回档案的每个超文本标记语言链接。

所以,我们可以操作这些字符串中的每一个并替换:

代码语言:javascript
运行
复制
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;
});
票数 0
EN

Stack Overflow用户

发布于 2014-06-11 04:18:26

brasofilo的解决方案在我身上起作用了,只做了一些小调整。

之前:

代码语言:javascript
运行
复制
$html = str_replace( 'href="http://example.com', 'href="http://example.org', $html );

之后:

代码语言:javascript
运行
复制
$html = str_replace( 'http://example.com', 'http://example.com/the_events', $html );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21387045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档