检查以下代码-
// Initiating shortcode. Place this code to any of your page to get your desired output.
add_shortcode( \'faq_page_content\', \'the_dramatist_faq_page_content\');
/**
* Rendering function
*/
function the_dramatist_faq_page_content() {
$terms = get_terms(\'sections\'); // Taxonomy name
echo \'<ul>\';
foreach($terms as $term) {
$posts = get_posts(
array(
\'post_type\' => \'questions\', // Post type
\'tax_query\' => array(
array(
\'taxonomy\' => \'sections\', // Taxonomy name
\'field\' => \'slug\',
\'terms\' => $term->slug
)
),
\'posts_per_page\' => -1
)
);
echo \'<li>\' . $term->name;
echo \'<ul>\';
foreach($posts as $post) {
echo \'<li><a href="\' . get_permalink( $post->ID ) . \'">\' . $post->post_title . \'</a></li>\';
}
echo \'</ul></li>\';
}
echo \'</ul>\';
}
在这里,我们启动一个名为
faq_page_content
. 通过插件加载此代码块,或
functions.php
和粘贴
[faq_page_content]
在所需页面中显示常见问题解答的快捷代码。您将获得所需的输出。
希望这有帮助。