function magazine_vertical($atts){
extract(shortcode_atts(array(
'slug' => '',
'title' => '',
'limit' => '5',
),$atts));
//The Query
query_posts('showposts=1&orderby=date&order=DESC&category_name='.$slug);
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
$return .= '<div class="magazine-vertical">';
$return .= '<div class="magazine-vertical-title-category"><span class="magazine-vertical-title">'.$title.'</span><span class="magazine-vertical-category"><a href="'. get_term_by('slug', $slug, 'category').'">More articles</a></span></div>';
$return .= '<div class="magazine-vertical-large">';
$return .= '<div class="magazine-vertical-large-1">';
$return .= '<div class="magazine-vertical-large-thumbnail">';
$return .= '<a href="'.get_permalink($post->ID).'" title="">'.get_the_post_thumbnail( $post_id, 'magazine-vertical').'</a>';
$return .= '</div>';
$return .= '<div class="magazine-vertical-large-subtitle">';
$return .= '<a href="'.get_permalink($post->ID).'" title="">'.get_the_title().'</a>';
$return .= '</div>';
$return .= '<div class="magazine-vertical-large-date">';
$return .= get_the_time('F j, Y');
$return .= '</div>';
$return .= '<div class="magazine-vertical-large-excerpt">';
$return .= get_the_excerpt();
$return .= '</div>';
$return .= '</div>';
$return .= '</div>';
endwhile;
endif;
//Reset Query
wp_reset_query();
return $return;
}
add_shortcode('magazine_vertical', 'magazine_vertical');
上面的函数产生:Catchable fatal error: Object of class stdClass could not be converted
问题出在这一部分:
$return .= '<div class="magazine-vertical-title-category"><span class="magazine-
vertical-title">'.$title.'</span>
<span class="magazine-vertical-category"><a href="'. get_term_by('slug', $slug, 'category').'">More articles</a></span></div>';
无法使用此代码(我需要此部分包含“更多文章”):
<a href="'. get_term_by('slug', $slug, 'category').'">More articles</a>
[magazine_vertical slug = my-category]是我在页面内使用的短代码。 我把它全部搞定了,除了这部分我必须从slug atts获得类别链接。
答案 0 :(得分:0)
在Wordpress中, $ output:Constant OBJECT,ARRAY_A或ARRAY_N
function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') { }
默认输出为object
,您无法将对象转换为字符串。
您可以尝试get_term_link( $term, $taxonomy );
参考:http://codex.wordpress.org/Function_Reference/get_term_link