我在WordPress中有一个短代码,显示作者的最后一篇文章,问题是我想要排除一个具体的作者(ID = 13)。短代码是下一个:
function latest_posts_c( $array ) {
global $post;
$defaults = array(
'show' => 3,
'excerpt' => 'false',
'post_type' => 'post',
);
extract( shortcode_atts( $defaults, $array ) );
$args = array(
'posts_per_page' => $show,
'post_type' => $post_type,
);
// Gets posts form database
$query = new WP_Query( $args );
// Displays posts if available
if( $query ) {
$i = 0;
while ( $query->have_posts()) : $query->the_post();
if ($i == 0)
$html = '<div class="column dt-sc-one-third first">';
else
$html .= '<div class="column dt-sc-one-third">';
$html .= '<article id="post-'.get_the_ID().'" class="'.implode(' ', get_post_class('blog-entry')).'">';
$html .= '<div class="blog-entry-inner">';
$html .= '<div class="entry-meta">';
$html .= ' <a href="'.get_permalink().'" title="'.get_the_title().'" class="entry_format"> </a>';
$html .= ' <div class="date">';
$html .= ' <p>'.get_the_date('M').' '.get_the_date('d').' <span>'. get_the_date('Y') .'</span> </p>';
$html .= ' </div>';
$html .= '</div><!-- .entry-meta -->';
if( has_post_thumbnail() ):
$html .= '<div class="entry-thumb">';
$html .= ' <a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_post_thumbnail(get_the_ID(), 'medium').'</a>';
$html .= '</div><!-- .entry-thumb -->';
endif;
$html .= '<div class="entry-details">';
if(is_sticky()):
$html .= ' <div class="featured-post"> <span class="fa fa-trophy"> </span> Destacado</div>';
endif;
$html .= ' <div class="entry-title">';
$html .= ' <h4><a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></h4>';
$html .= ' </div>';
$html .= ' <div class="entry-metadata">';
$html .= ' <p class="author">';
$html .= '<span class="fa fa-user"> </span>';
$html .= ' <a href="'.get_author_posts_url(get_the_author_meta('ID')).'" title="Ver todos las entradas de '.get_the_author().'">'.get_the_author().'</a></p>';
$categories = 0;/*get_the_category();*/
$separator = ', ';
$output = '';
if($categories){
$j = 0;
foreach($categories as $category) {
$output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "Ver todos las entradas en %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>';
$j++;
if ($j < count($categories)) $output .= $separator;
}
$html .= ' <p class="categories"><span class="fa fa-folder-open"> </span>'.$output.'</p>';
}
$html .= ' </div><!-- .entry-metadata-->';
$html .= ' <div class="entry-body">';
$html .= ' '.dttheme_excerpt(50);
$html .= ' <p><a href="'.get_permalink().'" title="'.get_the_title().'" class="dt-sc-button small read-more">';
$html .= ' Leer más <span class="fa fa-angle-double-right"> </span></a></p>';
$html .= ' </div>';
$html .= '</div><!-- .entry-details -->';
$html .= '</div><!-- .blog-entry-inner-->';
$html .= '</article>';
$html .= '</div>';
$i++;
endwhile;
}
$html .= '<div class="dt-sc-clear"></div>';
// Resets Post Data
wp_reset_postdata();
// Returns the results
return $html;
}
add_shortcode('latestposts_c', 'latest_posts_c');
如果有来自作者ID = 13的帖子,我添加了一个If来阻止代码,但问题是短代码没有显示任何内容。我也在使用“authors_in”来允许数组内的某些作者ID $ args和$ default但没有....任何想法?
答案 0 :(得分:0)
试试这个:
$args = array(
'posts_per_page' => $show,
'post_type' => $post_type,
'author' => '-13'
);
可以将author参数设置为包含/排除特定作者。
参考http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters