所以我有一个多站点WordPress环境,使用以下代码直接到另一个产品;然而,当在一个不规范的环境中(例如,如果CNAME
是aa.site.com
,那么ab.site.com
, ac.stie.com
和ad.site.com
都使用相同的代码库),该链接将引导您到正确的产品和页面或帖子,但是使用CNAME
-因为我希望子域在浏览产品时保持不变。
<a href="<?php echo get_permalink( $this->get_field('page_id.ID') ); ?>" class="button">Product 2</a>
到目前为止,让我们假设我们在http://ab.site.com/product_1/
上,并希望去http://ab.site.com/product_2/
。目前,网站最初设置的方式(不是我做的,我会在links.template.php中重写get_permalink函数来为此做准备;然而,现在这样做已经太晚了。还有太多东西会破裂。
基本上我正在寻找一个URL/URI
…事情有人能帮忙吗?
如果从头开始,这将是最好的方法:https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/link-template.php#L0
好了,我明白了。解决方案如下:
<a href="<?php
$url_endpoint = get_permalink( $this->get_field('page_id.ID') );
$url_endpoint = parse_url( $url_endpoint );
$url_endpoint = $url_endpoint['path'];
echo $url_endpoint; ?>" class="button">Go to next product</a>
:)