简体   繁体   English

WORDPRESS发布缩略图->链接发布

[英]WORDPRESS Post Thumbnail -> Link to post

I've made a custom metabox that if selected makes the post thumbnail the background of the site. 我制作了一个自定义元框,如果选中该框,则将帖子缩略图作为网站的背景。

Now I need that this post thumbnail has a link to the post. 现在,我需要此帖子缩略图具有指向该帖子的链接。

< ?php query_posts ('showposts=5$cat=2'); <?php query_posts('showposts = 5 $ cat = 2'); if (have_posts()) : ?> 如果(have_posts()):?>

  if ( has_post_thumbnail() && get_post_meta($post->ID, 'dbt_checkbox', true) ) { the_post_thumbnail('background'); } else {} ?> <?php endwhile; endif; ?> 

Wordpress documentation provides an example for this exact situation WordPress文档提供了这种情况的示例

<?php if ( has_post_thumbnail() ) : ?>
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    <?php the_post_thumbnail(); ?>
    </a>
<?php endif; ?>

However, I kind of hate opening and closing php tags so lightly. 但是,我有点讨厌这么轻松地打开和关闭php标签。 I'll try something to improve this answer. 我将尝试一些改进此答案的方法。

Edit : got it. 编辑 :知道了。 Please try this: 请尝试以下方法:

if ( has_post_thumbnail() && get_post_meta($post->ID, 'dbt_checkbox', true) ) {
    echo  '<a href="' . get_permalink( $post->ID ) . '" >';
    echo  get_the_post_thumbnail( $post->ID, 'background' );
    echo '</a>';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM