2016-11-29 156 views
1

我基本上想要在wordpress的「鏈接」部分創建一個類別,併爲該類別添加一些鏈接和標題。簡單的東西。在Worppress中單獨打印鏈接

然後,我希望能夠在我的模板文件中按照我的意願回顯鏈接和標題或有關鏈接的任何內容。最好在一個循環中,因爲我有一些頁面構建要在鏈接之前和之後執行。

我知道'category_before'和'category_after'存在,但他們不會做我需要的。

所以,我想,

<?php $args = array(
'orderby'   => 'name', 
'order'   => 'ASC', 
'limit'   => -1, 
'category'   => '3', 
'hide_invisible' => 1, 
'show_updated'  => 0, 
'echo'    => 1, 
'categorize'  => 0, 
'category_orderby' => 'name', 
'category_order' => 'ASC', 
'class'   => 'linkcat', 
'category_before' => '<tr><td>', 
'category_after' => '</td></tr>'); 
wp_list_bookmarks($args); 
?> 

但這幾件事錯了。除了鏈接文本和目的地之外,我不需要類別標題或任何其他內容。

我希望有一個'for'循環來循環所有的鏈接,我可以在裏面建立我的代碼段和鏈接,但是讓我知道是否有更好的方法。

感謝

編輯:更多信息

所以,我想:

<?php 
$taxonomy = 'link_category'; // Taken from the DB table 
$tax_terms = get_terms($taxonomy, array('hide_empty' => false)); 
?> 
<ul> 
<?php 
foreach ($tax_terms as $tax_term) { 
    echo $tax_term->name; 
} 
?></ul> 

這是我得到的最接近。這隻會返回有關該類別的信息,而不是該類別中的信息。

數據庫中的「wp_term_taxonomy」表中沒有關於我所做的實際類別的任何內容。

再次感謝

編輯: 這裏我指的是面積:

I want to show these 2 links

回答

0

您可能想嘗試get_bookmarks函數。

$bookmarks = get_bookmarks(array(
    'orderby'  => 'name', 
    'order'   => 'ASC', 
    'category_name' => 'category-name' 
)); 

// Loop through each bookmark and print formatted output 
foreach ($bookmarks as $bookmark) { 
    printf('<a class="relatedlink" href="%s">%s</a><br />', $bookmark->link_url, $bookmark->link_name); 
} 

https://codex.wordpress.org/Function_Reference/get_bookmarks

0

更多的控制,你可以使用函數get_terms

<?php 
//list terms in a given taxonomy 
$taxonomy = 'category'; // Pass default category or any custom taxonomy name 
$tax_terms = get_terms($taxonomy); 
?> 
<ul> 
<?php 
foreach ($tax_terms as $tax_term) { 
echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf(__("View all posts in %s"), $tax_term->name) . '" ' . '>' . $tax_term->name.'</a></li>'; 
} 
?> 
</ul> 

對於信息功能&其參數: https://developer.wordpress.org/reference/functions/get_terms/

+0

這似乎並沒有工作。您已使用「get_terms」但鏈接到「get_term」。既不返回任何東西。謝謝 – SamohtVII

+0

剛剛再次通過問題。你能提供什麼信息需要任何參考?你的期望值是多少? –