我修改了这段代码以用于一个基本的有用链接库,我在https://stackoverflow.com/questions/8643508/how-to-group-articles-by-tags/8645453#8645453.
<?php
$args = array(
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => 1,
\'taxonomy\' => \'useful_link_categories\',
);
foreach (get_categories($args) as $tax) :
$args = array(
\'post_type\' => \'useful-links\',
\'posts_per_page\' => -1,
\'orderby\' => \'title\',
\'orderby\' => \'ASC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'useful_link_categories\',
\'field\' => \'slug\',
\'terms\' => $tax->slug
)
)
);
if (get_posts($args)) :
?>
<h3><?php echo $tax->name; ?></h3>
<ul>
<?php foreach(get_posts($args) as $useful_link_post ): ?>
<li><a href="<?php get_field(\'url\'); ?>" target="_blank" title="Click here to read more"><?php echo $useful_link_post->post_title; ?></a></li>
<?php endforeach; ?>
</ul>
<?php
endif;
endforeach; ?>
不要使用此行:
<li><a href="<?php echo get_permalink($p); ?>"><?php echo $p->post_title; ?></a></li>
要将标题链接到帖子的永久链接,我想查询我添加到自定义帖子类型“有用链接”中的高级自定义字段(“url”)我试过这个:
<li><a href="<?php get_field(\'url\'); ?>" target="_blank" title="Click here to read more"><?php echo $useful_link_post->post_title; ?></a></li>
当然,它不起作用,我错过了很多重要的片段。相反,它链接了帖子的永久链接。我是WordPress后端开发的新手,如有任何帮助,将不胜感激。谢谢你-布莉