正在尝试将WordPress类别查询结果显示为背景图像

时间:2016-04-19 作者:Paubab

到目前为止,代码运行良好,但我想在li标记内将帖子缩略图显示为背景图像。尝试了很多变化,但都没有成功?代码如下:

<div class="main-slider" class="flexslider">
<ul class="slides">
    <?php 
    // Get all posts in \'slider\' category
    $post_categories = wp_get_post_categories( $post_id );
    $args = array( 
        \'post_type\' => array(\'Interaction\',\'Print\',\'Motion\',\'Image\',\'Sound\'),
        \'numberposts\' => 6,
        \'category_name\' => \'slider\'
    );
    $postQuery = get_posts($args);
    /*query_posts(array(\'post_type\' => \'Interaction\',
                        \'post_type\' => \'Print\',
                        \'post_type\' => \'Motion\',
                        \'post_type\' => \'Image\',
                        \'post_type\' => \'Sound\' 
                        )); */              
    foreach( $postQuery as $post ) : setup_postdata($post);
        if ( has_post_thumbnail() ) { ?>
            <li class="frontSlider"><?php the_post_thumbnail(\'feature-slider\'); ?>
                <a href="<?php echo get_permalink(); ?>" title="Go to <?php echo the_title(); ?>" rel="bookmark">
                    <div class="flex-captionWrap">
                        <p class="flex-caption"><?php echo get_post(get_post_thumbnail_id())->post_excerpt; ?></p><!-- Retrieves text string from Captions field in Media -->
                    </div>
                </a>
            </li>
        <?php 
        }
    endforeach; ?>
</ul><!-- .flexslider -->
</div><!-- .flexslider -->

1 个回复
SO网友:Nabeel Khan

您必须以想要显示的方式对输出进行编码。但是,您必须在html部分之前生成图像链接。

将图像保存在变量中$bgimage1;

在列表项中使用li和创建列表backgroun-image: <?php echo $bgimage1; ?>

相关推荐