PHP WordPress Post Thumbs Fallback
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP WordPress Post Thumbs Fallback相关的知识,希望对你有一定的参考价值。
//add support in functions file
add_theme_support( 'post-thumbnails');
add_image_size( 'home-feature', 590, 265, true ); // Homepage Feature Image
//function to call first uploaded image in functions file
function main_image() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image&order=desc');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', true);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$main=wp_get_attachment_url($num);
$template=get_template_directory();
$the_title=get_the_title();
print "<img src='$main' alt='$the_title' class='frame' />";
endif;
}
//goes in template to call image
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) {
echo get_the_post_thumbnail($post->ID,array(590, 265));
} else {
echo main_image();
} ?>
以上是关于PHP WordPress Post Thumbs Fallback的主要内容,如果未能解决你的问题,请参考以下文章
PHP 在WordPress中通知Old Post
PHP 单个post-wordpress的多个布局
php Wordpress中的核心帖子类型[wp-includes / post.php]
PHP Activar Post Thumbnails en Wordpress 2.9
php WordPress ALT immagine在evidenza post thumbnail
php 在Wordpress上自定义the_post_navigation