首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >限制字符串的文本数量

限制字符串的文本数量
EN

Stack Overflow用户
提问于 2016-02-12 14:47:40
回答 1查看 74关注 0票数 0

我正在使用WordPress,我有一个帖子,我想抓住,并将信息张贴在我的网站的头版。

我已经设法让它工作,但它张贴整篇文章,我想只张贴一个可能30个字符与“阅读更多”按钮在末尾。

下面是我正在使用的代码。因为我对Php比较陌生,所以我有点卡住了。

代码语言:javascript
复制
    <div class="entry-content">
        <?php if ( siteorigin_setting( 'blog_archive_content' ) == 'excerpt' ) the_excerpt(); else the_content(); ?>

        <?php
            wp_link_pages( array(
                'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'ultra' ) . '</span>',
                'after'  => '</div>',
                'link_before' => '<span>',
                'link_after'  => '</span>',
            ) );
        ?>
    </div><!-- .entry-content -->

下面是php文件的全部内容:

代码语言:javascript
复制
<?php
/**
 * @package ultra
 * @since ultra 0.9
 * @license GPL 2.0
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php if ( ! is_single() && has_post_thumbnail() && siteorigin_setting( 'blog_archive_featured_image' ) ) : ?>

        <div class="entry-thumbnail">
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                <?php the_post_thumbnail(); ?>
            </a>
        </div>

    <?php elseif ( is_single() && has_post_thumbnail() && siteorigin_setting( 'blog_archive_featured_image' ) ) : ?>

        <div class="entry-thumbnail">
            <?php the_post_thumbnail(); ?>

        </div>

    <?php endif; ?>
    <header class="entry-header">
        <?php the_title( sprintf( '<h1 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h1>' ); ?>

        <?php if ( 'post' == get_post_type() ) : ?>


        <?php endif; ?>
    </header><!-- .entry-header -->

    <div class="entry-content">
        <?php if ( siteorigin_setting( 'blog_archive_content' ) == 'excerpt' ) the_excerpt(); else the_content(); ?>

        <?php
            wp_link_pages( array(
                'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'ultra' ) . '</span>',
                'after'  => '</div>',
                'link_before' => '<span>',
                'link_after'  => '</span>',
            ) );
        ?>
    </div><!-- .entry-content -->



</article><!-- #post-## -->
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-12 17:42:38

您可以使用单词,这将给您定义的单词数量(而不是字符)。

代码语言:javascript
复制
<?php  echo wp_trim_words( get_the_content(), 5, '...<a href="'. get_permalink().'">Read More</a>' );?>

或者使用条纹宽度,这将给您一个字符限制。

代码语言:javascript
复制
<?php echo mb_strimwidth(get_the_content(), 0, 30, '...');?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35365439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档