1 回答

TA貢獻2051條經(jīng)驗 獲得超10個贊
無論如何,您的代碼似乎不完整: 如果我理解正確的話,您需要使用短代碼屬性。
function randm($atts) {
$args = array(
'post_type' => 'post',
'orderby'=> 'rand',
'category_name' => $atts['category'],
'posts_per_page' => 1,
);
/// ... your code
}
您可以使用它作為簡碼:
[randm category="Motor"]
如果你想使用多個類別,你可以分解字符串:
function randm($atts) {
$args = array(
'post_type' => 'post',
'orderby'=> 'rand',
'category_name' => explode(', ', $atts['category']),
'posts_per_page' => 1,
);
/// ... your code
}
并使用
[randm category="Motor, Second"]
如果您想確保存在默認值,您可以使用
function randm($atts) {
$atts = shortcode_atts( array(
'category' => 'Motor',
), $atts);
// Remaining code
}
- 1 回答
- 0 關(guān)注
- 143 瀏覽
添加回答
舉報