2011-11-20 56 views
-1

我有一個$postURL,它基本上包含一個wordpress發佈url。我檢索如下:如何在沒有url重寫規則的情況下動態更改wordpress帖子url

$postURL = get_permalink($postID); 

現在假設這個$ postURL是:

http://www.blogname.come/post-permalink/ 

我想改變這

http://www.blogname.come/post-permalink-1/ 

即在$的末尾添加-1 postURL並將其添加到新變量​​。

//函數以包括所需的JS和CSS在頭 功能wplikelockercss(){

// Include the CSS 
echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"".get_bloginfo('wpurl')."/wp-content/plugins/".basename(dirname(__FILE__))."/like-locker.css\"> \n"; 
//$postID = $_POST['post']; 
$postID = get_the_ID(); 
$postURL = get_permalink($postID); 
$newURL = substr($postURL, 0 -1). "-1"; 
//$newURL = "1-".$postURL; 


// Echo our per page post ID callback from facebok, when the user clicks like this function will be triggerd and their IP will be stored in the databse with the post ID 
echo " 
<script type=\"text/javascript\"> 

    FB.Event.subscribe('edge.create', function(href){ 

     var data = { post: '".get_the_ID()."', action: 'fbjax' }; 

     jQuery.post('".admin_url('admin-ajax.php')."', data, function(response) { 

      //location.reload(); 
      //location.href='http://www.blogname.net/how-thing-work-1'; 
      location.href='$newURL'; 

     }); 

    }); 

</script> \n 
"; 

}

,我有在適當的位置的上方設置的代碼。我得到$ postID,獲取$ postURL,然後嘗試創建一個newURL。 location.href然後使用這個$ newURL將用戶重定向到一個新頁面。

但是,如果是使用

$的newURL = SUBSTR($ postURL,0 -1)。 「-1」;

的$的newURL是

http://www.blogname.net/e-1或之前-1

如果我使用

$的newURL一些其它字符= 「1 - 」 $ postURL。

放在location.href重定向頁面

http://www.blogname.net/1-

回答

0

$newUrl = substr($postUrl, 0 -1) . "-1/";

+0

代碼變化,美的建議是行不通的。當我嘗試使用 location.href ='$ newURL'時,嘗試從$ postURL重定向到JavaScript中的$ newURL; 再次加載相同的頁面。 –

+0

你的意思是不工作?這段代碼只是剪掉$ postURL的最後一個符號,並在和處加上「-1 /」字符串。 – pomaxa

+0

我再次嘗試它,並location.href ='$ newURL';轉移到 HTTP://www.blogname.come/-1/ 而不是 HTTP://www.blogname.come/post-permalink-1/ –

1

使用htaccess的,Linux主機:

RewriteEngine On  
RewriteBase/
RewriteRule post-permalink-1$ post-permalink