我有以下自定义简码,它以定义的“类型”分类显示员工的自定义帖子类型。我正在尝试添加第二个属性,该属性将允许用户定义输出的布局样式,例如列或行。这是我设想的短代码的样子:
[staff type="international" style="rows"]
我想我拥有获取属性的所有编码,包括设置默认值,但我似乎无法弄清楚如何在其中获取 if 语句来更改输出。似乎它应该在第一条“$output .=" 行之前。
function get_staff($atts) {
extract( shortcode_atts( array(
'type' => 'international',
'style' => 'rows'
), $atts ) );
add_filter( 'posts_orderby' , 'posts_orderby_lastname' );
$loop = new WP_Query(
array (
'post_type' => 'staff',
'orderby' => 'title',
'staff-type' => $type,
'style' => $style
)
);
remove_filter( 'posts_orderby' , 'posts_orderby_lastname' );
if ($loop->have_posts()) {
$output = '<div class="staff">';
while($loop->have_posts()){
$loop->the_post();
$meta = get_post_meta(get_the_id());
// Attributes Array for Featured Image Below
$attr = array(
'title' => get_the_title(),
'alt' => get_the_title(),
'class' => 'img_frame'
);
$output .= '
<div class="row-fluid" style="border-bottom: 1px solid #EEE; margin-bottom: 16px; padding-bottom: 16px;">
<div class="span3">' . get_the_post_thumbnail($post->ID, 'small', $attr) . '</div>
<div class="span9"><h3>' . get_the_title() . '</h3>
' . get_the_content() . '
</div></div>
';
}
$output .= "</div>";
} else {
$output = 'No Staff Meet This Criteria Yet.';
}
return $output;
};
// Create Last Name Sort For Staff Custom Post Type
function posts_orderby_lastname ($orderby_statement)
{
$orderby_statement = "RIGHT(post_title, LOCATE(' ', REVERSE(post_title)) - 1) ASC";
return $orderby_statement;
}
add_shortcode('staff', 'get_staff');