我想創建一個顯示我的職位類型簡碼: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
我做到了,那是我如何開始這個簡碼,但我似乎無法找到我失蹤的東西? –
我想通了!謝謝。 –