如何防止图片标题显示在主页(帖子)内容中?

时间:2019-10-24 13:58:42

标签: php wordpress

我正在着陆页上显示帖子的图像和文字摘录。但是,我想防止图片标题出现在这些摘录中。

有快速的方法吗?

<?php while ( have_posts() ) : the_post() ?>
            <div id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>">
                <div class="entry-meta clearfix">
                    <h2 class="entry-title"><a href="<?php the_permalink() ?>" title="<?php printf(__('Permalink to %s', 'sandbox'), wp_specialchars(get_the_title(), 1)) ?>" rel="bookmark"><?php the_title() ?></a></h2>
                </div>
                <div class="entry-content">

                    <p class="thePic clearfix">
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_image('thumbnail'); ?></a>
                    </p>                    
                    <p>
                        <?php the_content_rss('', TRUE, '', 40); ?><a href="<?php the_permalink() ?>" title="<?php printf(__('Permalink to %s', 'sandbox'), wp_specialchars(get_the_title(), 1)) ?>" rel="bookmark">Read More</a>
                    </p>
                </div><!-- .entry-content -->                   
            </div><!-- .post -->
<?php endwhile ?>

2 个答案:

答案 0 :(得分:1)

将此代码添加到您的functions.php

function excerpt_bz( $content, $limit=25, $endPoints = '[...]', $tags_accepts = '' ) {  
    $excerpt = explode(' ', strip_tags($content, $tags_accepts), $limit);
    if (count($excerpt)>=$limit) {
        array_pop($excerpt);
        $excerpt = implode(" ",$excerpt).' '.$endPoints;
    } else {
        $excerpt = implode(" ",$excerpt);
    }

    return $excerpt;
}

请注意,这会拉出内容并剪切,然后传递允许的数据

<?php while ( have_posts() ) : the_post() ?>
            <div id="post-<?php the_ID() ?>" class="<?php /*sandbox_post_class()*/ ?>">
                <div class="entry-meta clearfix">
                    <h2 class="entry-title"><a href="<?php the_permalink() ?>" title="<?php printf(__('Permalink to %s', 'sandbox'), wp_specialchars(get_the_title(), 1)) ?>" rel="bookmark"><?php the_title() ?></a></h2>
                </div>
                <div class="entry-content">

                    <p class="thePic clearfix">
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                            <!--here you have greater control -->
                            <figure>
                                <?php get_the_post_thumbnail('thumbnail'); ?>
                            </figure>
                        </a>
                    </p>                    
                    <p>
                        <!-- use ( note that this function you need to fill the field in the panel in wp )-->
                        <?php the_excerpt(); ?>
                        <!-- or (note that this pulls the content and cuts it and you pass the allowed data) -->
                        <?php echo excerpt_bz( get_the_content(), 500, '...', '<a><p><br><strong><em>' ) ?>

                        <a href="<?php the_permalink() ?>" title="<?php printf(__('Permalink to %s', 'sandbox'), wp_specialchars(get_the_title(), 1)) ?>" rel="bookmark">Read More</a>
                    </p>
                </div><!-- .entry-content -->                   
            </div><!-- .post -->
<?php endwhile ?>

答案 1 :(得分:0)

通过将“ the_excerpt”替换为“ the_content_rss”来获得

            <div id="post-<?php the_ID() ?>" class="<?php sandbox_post_class() ?>">
                <div class="entry-meta clearfix">
                    <h2 class="entry-title"><a href="<?php the_permalink() ?>" title="<?php printf(__('Permalink to %s', 'sandbox'), wp_specialchars(get_the_title(), 1)) ?>" rel="bookmark"><?php the_title() ?></a></h2>
                </div>
                <div class="entry-content">

                    <p class="thePic clearfix">
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_image('thumbnail'); ?></a>
                    </p>                    
                    <p>
                        <?php the_excerpt('', TRUE, '', 40); ?><a href="<?php the_permalink() ?>" title="<?php printf(__('Permalink to %s', 'sandbox'), wp_specialchars(get_the_title(), 1)) ?>" rel="bookmark"><div class="read-more">Read More</div></a>
                    </p>
                </div><!-- .entry-content -->                   
            </div><!-- .post -->
<?php endwhile ?>
相关问题