まず第二に、これができますあなたのfunctions.php にこれを追加...あなたのファイルにそれをコピーして貼り付け、この
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
}
ため
をあなたのfunctions.phpファイルをチェック次に、あなたのテンプレートページ上のような何かにあなたのコードを変更する
function get_the_post_thumbnail_url($post_id = NULL) {
global $id;
$post_id = (NULL === $post_id) ? $id : $post_id;
$src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'full');
$src = $src[0];
return $src;
}
画像srcを返し、ちょうど全体のimgタグを印刷しない
:
これは
は、あなたが完全なimgタグのコードはいずれかを使用するだけで、印刷したい場合は、背景画像
<?php if (has_post_thumbnail()) { ?>
<div id="slider" style="background-image:url(<?php echo get_the_post_thumbnail_url($post->ID, 'large'); ?>); background-position: center center;">
</div>
<?php
}else{
?>
<img src="<?php bloginfo('template_directory');?>/images/blank.jpg" alt="" />
<?php
}
?>
これはそれに適用される背景イメージを持つdiv要素を生成しなければならないとしました次の
if (has_post_thumbnail()) {
?>
<?php the_post_thumbnail(); // just the image ?>
<?php the_post_thumbnail('thumbnail'); // just the thumbnail ?>
<?php the_post_thumbnail('medium'); // just the Medium Image ?>
<?php the_post_thumbnail('large'); // just the Medium Image ?>
<?php
// adding a 200x200 height and width along with a class to it.
the_post_thumbnail(array(200,200), array('class' => 'alignleft'));
?>
<?php
// Adding a few classes to the medium image
the_post_thumbnail('medium', array('class' => 'alignleft another_class'));
?>
<?php
}
マーティ..
どうしたのですか? –
私はそれを実行するときに何も表示されません。私はthe_thumbnailのような別のものを試しましたが、まだ何も表示されていません – jorame
あなたはそれがループに入っていると確信していますか? – KDM