Wordpress 显示快捷代码中的特色图像-当前只有标题和摘录
我目前有一个从WP初学者那里提取的函数,它允许我创建一个快捷码,将粘贴在网站上的帖子拉到我想要的任何地方 我需要这也显示了特色的形象,但不知道如何让这个工作目前。当前短代码如下所示:Wordpress 显示快捷代码中的特色图像-当前只有标题和摘录,wordpress,Wordpress,我目前有一个从WP初学者那里提取的函数,它允许我创建一个快捷码,将粘贴在网站上的帖子拉到我想要的任何地方 我需要这也显示了特色的形象,但不知道如何让这个工作目前。当前短代码如下所示: function wpb_latest_sticky() { /* Get all sticky posts */ $sticky = get_option( 'sticky_posts' ); /* Sort the stickies with the newest ones at the top */ r
function wpb_latest_sticky() {
/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );
/* Sort the stickies with the newest ones at the top */
rsort( $sticky );
/* Get the 5 newest stickies (change 5 for a different number) */
$sticky = array_slice( $sticky, 0, 1 );
/* Query sticky posts */
$the_query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) );
// The Loop
if ( $the_query->have_posts() ) {
$return .= '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$return .= '<li><a href="' .get_permalink(). '" title="' . get_the_title() . '">' . get_the_title() . '</a><br />' . get_the_excerpt(). '</li>';
}
$return .= '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
return $return;
}
add_shortcode('latest_stickies', 'wpb_latest_sticky');
函数wpb_latest_sticky(){
/*得到所有粘帖*/
$sticky=get_选项('sticky_posts');
/*把胶粘物和最新的放在最上面*/
rsort($sticky);
/*获取5个最新的胶粘物(将5个更改为不同的数字)*/
$sticky=array\u slice($sticky,0,1);
/*查询粘帖*/
$the_query=new WP_query(数组('post__in'=>$sticky',ignore_sticky_posts'=>1));
//环路
if($the\u query->have\u posts()){
$return.='';
while($the\u query->have\u posts()){
$the_query->the_post();
$return.='
'。获取摘录();
}
$return.='
';
}否则{
//没有找到帖子
}
/*恢复原始Post数据*/
wp_reset_postdata();
return$return;
}
添加快捷码(“最新粘性”、“wpb最新粘性”);
这就是我在帖子页面上的方式:
<?php if ( has_post_thumbnail() && !is_search() ) { ?>
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( esc_html__( 'Permalink to ', 'quark' ) . '%s', the_title_attribute( 'echo=0' ) ) ); ?>">
<?php the_post_thumbnail( 'post_feature_full_width' ); ?>
</a>
任何帮助都将不胜感激 while($the\u query->have\u posts()){
while ( $the_query->have_posts() ) {
$the_query->the_post();
$return .= '<li><a href="' .get_permalink(). '" title="' . get_the_title() . '">' . get_the_title() . '</a><br />' . get_the_excerpt() . '<br/>' . get_the_post_thumbnail() . '</li>';
}
$the_query->the_post();
$return.='
'。获取摘录()。
'。获取发布缩略图()。 ';
}
你有没有试过获取帖子缩略图()这很有效,吉姆的回答给了我500个错误,但安迪似乎已经解决了。是否有添加类到标题、摘录和特色文章中以便于css编辑?非常感谢您的帮助。您可以这样做来添加类:
。获取摘录()
。获取发布缩略图(“$post->ID”,“full”,数组('class'=>'yourImageClass')。
0向下投票如下:获取发布缩略图($post->ID,'缩略图',数组('class'=>'alignleft'));