我正在開發一個wordpress主題。但我可以爲自定義帖子添加特徵圖片。 起初我創建的functions.php一個自定義後功能圖片不能在wordpress中工作
<?php
function rithemes_post_type() {
register_post_type('portfolio_items',
array(
'labels' => array(
'name' => __('Portfolio-items'),
'singular_name' => __('Portfolio-item'),
'add_new' => __('Add New '),
'add_new_item' => __('Add New Portfolio-item'),
'edit_item' => __('Edit Portfolio-item'),
'new_item' => __('New Portfolio-item'),
'view_item' => __('View Portfolio-item'),
'not_found' => __('Sorry, we couldn\'t find the Slide you are looking for.')
),
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => true,
'menu_position' => null,
'has_archive' => true,
'hierarchical' => true,
'capability_type' => 'post',
'rewrite' => array('slug' => 'Portfolio-items'),
'supports' => array('title', 'editor', 'custom-fields','thumbnail')
)
);
add_action('init', 'rithemes_post_type');
?>
然後我在index.php中的代碼中的functions.php以下以下
add_theme_support('post-thumbnails', array('portfolio_pretty','portfolio_items','portfolio_single'));
add_image_size('blog_post_single', 615, 390, true);
add_image_size('portfolio_pretty', 610, 300, true);
add_image_size('portfolio_single', 440, 275, true);
然後我代碼以下如下
<?php
global $post;
$args=array('posts_per_page'=> 6, 'post_type'=>'portfolio_items');
$myposts=get_posts($args);
foreach($myposts as $post): setup_postdata($post);?>
<div class="three columns category trains">
<h5><?php the_title(); ?></h5>
<?php $songkhipto=get_post_meta($post->ID, 'songkhipto', true); ?>
<p>
<?php echo $songkhipto; ?>
</p>
<div class="portofoliothumb">
<div class="portofoliothumboverlay fouroverlay">
<div class="viewgallery fourgallery">
<a data-gal="prettyPhoto[gallery]" href="<?php the_post_thumbnail('portfolio_pretty'); ?><img src="<?php echo get_template_directory_uri(); ?>/images/playgal.png" class="left galleryicon" alt=""> Gallery</a>
</div>
<div class="inner fourdetail">
<a class="projectdetail" href="<?php the_permalink(); ?>">+ Project Details</a>
</div>
</div>
<img src="<?php the_post_thumbnail('portfolio_single'); ?>" class="fourimage" alt=""/>
</div>
</div>
<?php endforeach; ?>
但沒有顯示特徵圖像。這隻顯示圖像名稱。我需要幫助
仍然沒有工作,那裏什麼也沒有顯示.. – 2014-09-21 18:36:04
對不起,更新了我的答案。 – manishie 2014-09-21 18:53:20