从the_permalink()获取父网址;

问题描述 投票:0回答:2

所以这是我的问题。 Wordpress PHP功能

the_permalink();

给我这个网址:http://www.website.com/author-20/article-title

我基本上需要他的父URL。我怎么才能得到它? (http://www.website.com/author-20/

php wordpress parent permalinks
2个回答
0
投票

如果链接始终以这种方式构建,则可以在最后一个/之后剪切该部分。在PHP中这样做的方法是使用函数substrstrrpos

$parentUrl = substr($permaLink, 0, strrpos($permaLink, '/'));

substr切出一部分字符串,从第二个参数开始,第三个参数的长度。

strrpos搜索字符串中字符的最后位置。

如果链接结构表示后父结构,请考虑this question from the wordpress stackexchange community


1
投票

你可以使用dirname() function

$url = "http://www.website.com/author-20/article-title";
var_dump(dirname($url));

输出:

http://www.website.com/author-20
© www.soinside.com 2019 - 2024. All rights reserved.