Wordpress回退映像
我从以前的开发人员那里得到了一个项目,他正在使用这个代码生成缩略图。我需要添加一个默认的回退映像,我不确定最佳做法Wordpress回退映像,wordpress,wordpress-theming,thumbnails,image-generation,Wordpress,Wordpress Theming,Thumbnails,Image Generation,我从以前的开发人员那里得到了一个项目,他正在使用这个代码生成缩略图。我需要添加一个默认的回退映像,我不确定最佳做法 <?php get_header(); ?> <?php get_sidebar(); ?> <div id="container"> <?php if(have_posts()) : ?> <?php while(have_posts()) : the_post(); ?>
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="container">
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="entry">
<?php the_content(); ?>
</div>
<?php $categories = get_categories(array('orderby'=>'order','number'=>'13'));
$wud = wp_upload_dir();
$width = get_option('thumbnail_size_w');
$height = get_option('thumbnail_size_h');
$exclude_cats = array(1, 27); // Array of category ID's to exlude from this page
?>
<div id="gallery">
<ul class="cat-list">
<?php foreach ($categories as $cat) {
if (!in_array($cat->cat_ID, $exclude_cats)) : ?>
<li class="cat-item cat-item-<?php echo $cat->cat_ID; ?>">
<a href="<?php echo get_category_link( $cat->term_id ); ?>" title="View all artists under the <?php echo $cat->cat_name; ?> category">
<div class="cat-ss" style="position: relative; width: <?php echo $width; ?>px; height: <?php echo $height; ?>px; overflow: hidden;">
<?php $artists = get_posts('category=' . $cat->cat_ID . '&orderby=rand');
foreach ($artists as $artist) {
$name = get_the_title( $artist->ID );
$thumb = $wud['baseurl'] . '/thumb-' . sanitize_title( $name ) . '-' . $width . 'x' . $height . '.jpg'; ?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $name; ?>" title="<?php echo $name; ?>" width="<?php echo $width; ?>" class="cat-ss-image" height="<?php echo $height; ?>" style="position: absolute; top: 0; left: 0;" />
<?php } ?>
<div class="cat-ss-caption png" style="position: absolute; bottom: 0;"><h3><?php echo $cat->cat_name; ?></h3></div>
</div>
</a>
</li>
<?php endif;
} ?>
<ul>
</div>
<div style="clear: both"></div>
</div>
<?php endwhile; ?>
<?php else : ?>
<div class="post">
<h2><?php _e('Not Found'); ?></h2>
</div>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
不管您的代码是什么,您都应该查看一下,然后使用它输出缩略图或回退图像
在我的许多网站上都很有魅力。你可以在我链接到的法典页面中找到例子。看起来他的代码很有用
<?php $thumb = $wud['baseurl'] . '/thumb-' . sanitize_title( $name ) . '-' . $width . 'x' . $height . '.jpg'; ?>
因此,要使其成为条件if/else语句(如果它不是空的话),请渲染图像缩略图,如果它是空的话,请执行以下操作(添加要渲染图像所需的任何其他代码):
“alt=”“title=”“width=”“class=“cat ss图像”height=”“style=“位置:绝对;排名:0;左:0;" />
您应该编辑您的问题,使其仅包含您所指的相关代码。
<?php if(!empty $thumb) { ?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $name; ?>" title="<?php echo $name; ?>" width="<?php echo $width; ?>" class="cat-ss-image" height="<?php echo $height; ?>" style="position: absolute; top: 0; left: 0;" />
<?php } else { ?>
<img src="yourfallback.jpg" style="position: absolute; top: 0; left: 0;">
<?php } ?>