2011-09-19 44 views
-1

我想在wordpress頁面內進行鏈接,並說我的網址是www.test.com,例如我有www.test.com/p1 www.test.com/p2和www .test.com/p3頁面,我想在p3中添加p1和p2鏈接,從admin端..現在,我只是插入和相同的p2 ..但如果我的permanlink更改比我需要再次更改內容..是有任何解決這個..所以我可以插入只有ID的頁面,它會自動將其轉換爲鏈接。從管理員頁面鏈接後端wordpress 3.1

回答

1

您可以使用短代碼API來生成與post-id的鏈接。 當您添加以下代碼到你的function.php

add_shortcode('permalink', 'permlink_replace_func'); 

function permlink_replace_func($atts){ 

    extract(shortcode_atts(array(
     'id' => '', 
     'lable' => 'link' 
    ), $atts)); 

    $permpost = get_post($id); 
    $html = '<a href="'.get_permalink($id).'" >'; 

    if ($lable==null) { 
     $html .= $permpost->post_title; 
    } else { 
     $html .= $lable; 
    } 

    $html .= '</a>'; 

    return $html; 
} 

您可以在文章的內容區域中輸入一個字符串像[permalink id ="8" lable="hallo world"]得到一個鏈接到每個ID另一篇文章。

有關簡碼的更多信息,請訪問WordPress Shortcode API

相關問題