2009-08-20 36 views
1

我的網址爲WordPress的帖子是這樣的: http://localhost:8888/blabla/book/yes-vi-testar在WordPress的使用上the_permalink的PHP SUBSTR()

使用the_permalink()會產生「http://localhost:8888/blabla/book/yes-vi-testar」但我想剪頭34個字符來得到這樣一個字符串「是-VI-testar」。如何在這種情況下使用php substr?我很困惑...我試過

<?php 
    $friendlypermalink = substr(the_permalink(), 34); 
?> 

但這並不能解決問題。

回答

2

使用get_the_permalink獲得永久沒有這麼

substr(get_the_permalink(), .............); 

很多的WordPress的功能,在使用get作爲「回報」交替呼應它

操作詞。 IE:get_the_timeget_the_content

the_title是我相信沒有這個選項的唯一一個。對於the_title你必須通過兩個空參數(之前和之後分隔符)以及一個真或假的......此刻

the_title("","",true); 
-3

正如Chacha所說,使用get_the_permalink()。然後,您可以這樣做:

$url = get_the_permalink(); 
$text = substr($url, strrpos($url, '/') + 1); 

//or 

preg_match('~[^/]+$~', get_the_permalink(), $m); 
$text = $m[0]; 
+0

這樣不是回報「是-VI-testar」不知道? – bisko

+0

@bisko:是的,是不是問題是如何得到的? –

+0

$ url = get_permalink();訣竅 –