首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Worppress中单独打印链接

在Worppress中单独打印链接
EN

Stack Overflow用户
提问于 2016-11-29 04:10:30
回答 2查看 38关注 0票数 1

我基本上希望在wordpress的“链接”部分创建一个类别,并为该类别添加一些链接和标题。简单的东西。

然后,我想要能够,在我的模板文件,回声链接和标题或任何有关链接的个别我喜欢。最好是在一个循环,因为我有一些页面建设之前和之后的链接。

我知道'category_before‘和'category_after’是存在的,但是他们不会做我需要的事情。

所以我试了一下

代码语言:javascript
复制
 <?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‘循环,将循环所有链接,我可以只构建我的代码部分和链接在其中,但让我知道是否有更好的方法。

谢谢

编辑:更多信息

所以我试着:

代码语言:javascript
复制
<?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>

这是我得到的最接近的。这只返回有关类别的信息,而不是类别中的信息。

在DB中的"wp_term_taxonomy“表中没有关于我创建的实际类别的任何内容。

再次感谢

编辑:这里是我指的领域:

我想展示这两个链接

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-11-29 22:29:06

您可能需要尝试get_bookmarks函数。

代码语言:javascript
复制
$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 );
}

书签

票数 0
EN

Stack Overflow用户

发布于 2016-11-29 05:13:21

要获得更多的控制,您可以使用函数get_terms

代码语言:javascript
复制
<?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>

关于info函数及其参数:条款/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40857661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档