2016-10-15 7 views
0

wp_insert_linkを正しく使用する方法がわかりません。 wp_insert_linkは何も表示しません

は、私が参照

<?php 
    $linkdata = array(
    'link_name' => 'WordPress Code Reference', 
    'link_url' => 'https://developer.wordpress.org/reference' 
    ); 

    $link_id = wp_insert_link($linkdata); 
?> 

からのコードを使用しても内部の<div><a>または<p>ようにしたりすることなく、いくつかのHTMLタグに統合しようとしましたが、ページに結果を見ることができません。例えば

は私が

<a href =<?php wp_insert_link('users.php')?>>test</a> 

<a href =<?php echo wp_insert_link('users.php')?>>test</a> 

をしようとしたハイパーリンクが表示されますが、それは任意のページにリダイレクトされていません。

私が紛失しているものをお勧めします。

The ID of the link (whether new or updated) on success. 
On error, 0 if $wp_error is set to false. 
A WP_Error object if it is set to true. 

その関数がないことを表示するために、あなたのWPのインストール中にリンクを追加するために使用されます。ドキュメントとして

答えて

0

は、関数が戻ると言います。あなたがリンクしたいページの現在のIDですつのパラメータを取りますthe_permalink($id)使用するリンクを表示するために


は、ドキュメントが言うように:

Retrieves the permalink for the current page (if in The Loop) or any arbitrary page ID if passed as the first argument. All arguments are optional. All arguments default to false. 
If $id is passed, it will be the id of the page whose link is returned. 
$leavename can be used to toggle off the switching out of "%pagename%" in permalinks. 
$sample returns a sample permalink. 

既存のページにリンクする例:

<a href="<?php the_permalink(); ?>">permalink</a> 

<a href="<?php the_permalink($pageID); ?>">permalink</a> 

現在のページをリンクする例を

関連する問題