我开发了这个定制的WP主题:http://www.asper-eritrea.com/
正如你可以看到的文章摘录(在首页),它显示了我的帖子的第一步。
为此,我使用以下代码:
<div class="entry-content">
<?php
if (!has_post_thumbnail() && catch_that_image()) {
if ( get_the_post_thumbnail($post_id) != '' ) { // Se l'articolo non ha un'immagine predefinita:
echo '<span class="thumb"><a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
the_post_thumbnail();
echo '</a><span>';
} else {
echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
echo '<img src="';
echo catch_that_image();
echo '" alt="" />';
echo '</a>';
}
}
?>
<?php
if(has_post_thumbnail()) {
echo '<span class="thumbnail"><a href="'; the_permalink(); echo '">';the_post_thumbnail(array(100,100)); echo '</a></span>';
}
?>
<?php the_excerpt(); ?>
<?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'your-theme' ) . '&after=</div>') ?>
</div> <!-- .entry-content -->为了检查是否存在*特色的免疫,我使用has_post_thumbnail()函数,检查一个帖子是否附加了一个,然后检索我使用的这个免疫函数:the_post_thumbnail()函数。
为了收回第一个处理方法,我使用了名为catch_that_image()的自定义函数,这个函数声明在我的*functions.php**文件中:
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches[1][0];
/*if(empty($first_img)) {
$first_img = "/path/to/default.png";
}*/
return $first_img;
}我想要有以下的行为:如果在一个帖子中有一个免疫,但特色的免疫没有设置,那么在文章中使用第一个免疫。如果在文章中有更多的关于免疫,但特色的免疫是设置,然后显示特色的免疫的帖子摘录。
在functions.php文件中,我还添加了缩略图支持:
function aspertheme_setup() {
add_theme_support( 'post-thumbnails' );
}现在我的问题是,文章的第一次处理是正确的,但我不能设置一个特色的,因为当我创建一个新的帖子时,我没有缩略图设置的框。
为什么?我遗漏了什么?我怎样才能解决这个问题?
Tnx
安德里亚
编辑1:在页面右上角的"Screen Options"选项卡中,我只有以下内容:

发布于 2014-10-08 09:33:39
您在页面右上角的“屏幕选项”选项卡中签入仪表板了吗?

发布于 2014-10-08 09:49:28
您是检查屏幕选项直接在登陆页的wordpress“仪表板”,不要检查那里,检查内部posts或pages在那里你会发现屏幕选项,包括特色图像,评论等。
https://stackoverflow.com/questions/26253398
复制相似问题