我想创建一个显示我的职位类型简码:advanced_topic但要添加的类别参数如如何将类别参数添加到短代码?
[高级课题类别=“假释”]
显示下唯一主题该类别。
这是我到目前为止的代码,但我觉得我失去了一些东西,因为它不工作......任何帮助表示赞赏。谢谢。
function display_advanced_topics(){
extract(shortcode_atts(array('category_name' => 'criminal-records'), $args)); // $categoryName variable will be initialized to 'criminal-records' if the shortcode is missing the 'category' parameter
$string = '';
$args = array(
'post_type' => 'advanced_topic',
'posts_per_page' => -1,
'post_status' => 'publish',
'category_name' => $categoryName
);
$query = new WP_Query($args);
if($query->have_posts()){
$string .= '<div class="advanced-topics">';
while($query->have_posts()){
$query->the_post();
$string .=
'<div class="row advanced-topic">'
.'<div class="content">
<div class="title"><?php get_the_title(); ?></div>
</div>'
.'</div>';
}
$string .= '</div>';
}
wp_reset_postdata();
return $string;
}
add_shortcode('advanced-topics', 'display_advanced_topics');
您应该阅读Codex关于如何使用属性制作简码的方法。你的失踪。 https://codex.wordpress.org/Function_Reference/shortcode_atts – Christina
我做到了,那是我如何开始这个简码,但我似乎无法找到我失踪的东西? –
我想通了!谢谢。 –