zoukankan      html  css  js  c++  java
  • wordpress列表页如果文章没有缩略图就显示默认图片

      有时我们在设计wordpress模板时需要考虑是否有特色图,在分类页上如果一些文章有缩略图一些没有那就有点参差不齐不美观,有没办法设置如果没有文章缩略图则自动显示默认图呢?可以的,随ytkah一起来看看。在category.php文件中,我们可以通过has_post_thumbnail()先判断是否有特色图,如果有就调用特色图,如果没有就调用默认图,如/images/default.jpg,代码如下

                    <div class="list">
                        <?php if(have_posts()) : ?>
                            <?php while(have_posts()) : the_post(); ?>
                                <div class="item wow zoomIn">
                                    <a href="<?php the_permalink(); ?>">
                                        <img src="<?php if ( has_post_thumbnail() ): ?><?php the_post_thumbnail_url( 'full' ); ?>" alt="<?php the_title(); ?>" width="520" height="300">
                                                    <?php else: ?><?php echo '/images/default.jpg'; ?>" alt="<?php the_title(); ?>" width="520" height="300">
                                                    <?php endif; ?>
                                        <strong><?php the_title(); ?></strong>
                                        <p><?php the_excerpt(); ?></p>
                                    </a>
                                </div>
                            <?php endwhile; ?>
                            <?php posts_nav_link(); ?>
                        <?php else : ?>
                            no products!
                        <?php endif; ?>
                    </div>
    

      保存上传,刷新缓存,打开分类页看看是不是已经调用默认缩略图了。

  • 相关阅读:
    Mishka and Interesting sum
    Tree Restoring
    LIB 配置文件读写器
    WCF 采用net.tcp协议实践
    MVC ViewEngineResult实际上是一种设计
    MVC 依赖注入扩展
    功能权限设计
    代理上网荟萃
    MD5算法 简介
    MVC _ViewStart文件的作用
  • 原文地址:https://www.cnblogs.com/ytkah/p/11526591.html
Copyright © 2011-2022 走看看