【问题标题】:Updated: Featured Image behind post title on WordPress Homepage (columns)更新:WordPress主页上帖子标题后面的特色图片(列)
【发布时间】:2014-07-03 03:11:18
【问题描述】:

我有一个包含多个帖子的 WordPress 网站。在主页上,我设置了一个插件 (https://wordpress.org/plugins/column-posts/),以便显示三列最新帖子。这很好用,我可以在 CSS 中设置列​​的样式。但是,我希望每个帖子的特色图片成为该帖子专栏的背景?知道我会如何做到这一点吗?

<ul>
            ';
        }

        // thumbnail
        $thclear = '';
        $bullet = '<li style="background:url(<?php'.$thumb.'?>);">';
        $thumb = '';
        if ( $args['thumb'] ) {
            if ( has_post_thumbnail($post->ID) ) {
                //$bullet = '';
                $thclear = '<div style="clear:both;"></div>';
                $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), $args['tsize'], false, array('class'=>"alignthumb"));
            }
        }
        $ppost .= $bullet .'<a href="'.get_permalink($post->ID).'" title="'.sprintf(__('Article %s published at %s', 'cp'), $title_full, date_i18n(__('F j, Y g:i a'), strtotime($post->post_date)) ).'">'.$title.'</a>';

        // excerpt
        if ( $args['excerpt'] ) {
            $ppost .= '<p>' .get_the_excerpt() .'</p>' .$thclear .'</li>';
        }
        else{
            $ppost .= $thclear .'</li>';
        }

        if ($args['class'] == 'P' && $args['col_cnt'] == $args['col_post'])
            $ppost .= '
            </ul>

我想我可以像这样将变量插入 li 样式:

<li style="background:url(<?php'.$thumb.'?>);">

但是,它根本没有回显任何内容,并且肯定没有图像 src。任何让它回显 $thumb 作为背景图像或在该代码中的某处插入背景图像的方法。谢谢!!

谢谢!

【问题讨论】:

    标签: php wordpress image


    【解决方案1】:
    $image=wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    
    <img class="whatever" src="<?php echo $image;?>" />
    

    css

    .whatever {
      z-index: -1;
    }
    

    【讨论】:

    • WordPress 没有将 " /> 转换为 src url?我是否正确编码了回显请求?它似乎没有处理它,所以它只是在 html 中显示为 " />
    • 我用更多信息更新了我的问题。任何帮助将不胜感激。谢谢!
    • 您在定义 $thumb 之前使用它。在 li 之前用你的 if 语句定义它。删除
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    相关资源
    最近更新 更多