我在WordPress中发帖的网址如下所示:http://localhost:8888/blabla/book/yes-vi-testar
使用 the_permalink()
将生成“http://localhost:8888/blabla/book/yes-vi-testar " but I want to cut the first 34 characters to get a string like " yes-vi-testar” . 在这种情况下如何使用php substr?我很困惑......我试过了
<?php
$friendlypermalink = substr(the_permalink(), 34);
?>
但这并不成功 .
2 回答
使用
get_the_permalink
获取固定链接而不回显它所以
很多Wordpress函数都使用
get
替代get
作为操作词 . IE:get_the_time
,get_the_content
等the_title
是我认为唯一没有此选项的人 . 对于the_title
,你必须传递两个空参数(前后分隔符)和一个真或假......目前还不确定正如Chacha所说,使用get_the_permalink() . 然后你可以这样做: