Php 如何在WP主题中正确添加特色的immage(缩略图)支持?为什么我能';不加一个特色的伊玛吉?
我开发了这个定制WP主题: 正如你在主页上看到的,这是我的帖子中的第一个页面 为此,我使用以下代码:Php 如何在WP主题中正确添加特色的immage(缩略图)支持?为什么我能';不加一个特色的伊玛吉?,php,content-management-system,wordpress-theming,wordpress,Php,Content Management System,Wordpress Theming,Wordpress,我开发了这个定制WP主题: 正如你在主页上看到的,这是我的帖子中的第一个页面 为此,我使用以下代码: <div class="entry-content"> <?php if (!has_post_thumbnail() && catch_that_image()) { if ( get_the_post_thumbnail($post_id) != '' ) { // Se l'articolo non
<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 -->
现在我的问题是,帖子的第一个页面显示正确,但我无法设置特色页面,因为创建新帖子时,我没有缩略图设置框
为什么??我错过了什么?我如何解决这个问题
Tnx
安德烈
编辑1:在页面右上角的“屏幕选项”选项卡中,我只有以下内容:
您是否在仪表板中选中了页面右上角的“屏幕选项”选项卡
您直接在wordpress的登录页“仪表板””中检查屏幕选项,不要在那里检查,在帖子或页面中检查,您将在那里找到屏幕选项,包括特色图像,评论等。不,我没有“特色图像”的声音。我已经编辑了我的原始帖子,包括我在屏幕选项中的屏幕显示,你确定你调用了aspertheme_设置功能,还是只是存在?尝试直接在your functions.php的really early中插入这个add_theme_support函数。解决方法:我忘记添加add_操作('after_setup_theme','aspertheme_setup');函数定义后
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;
}
function aspertheme_setup() {
add_theme_support( 'post-thumbnails' );
}