首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将帖子内容限制为类别页面中的字符数- wordpress

如何将帖子内容限制为类别页面中的字符数- wordpress
EN

Stack Overflow用户
提问于 2014-05-15 23:29:41
回答 5查看 1.4K关注 0票数 1

我有几个类别,其中之一是“旅行”每个帖子都包含一个关于旅行的小简介。我如何显示一个分类页面,显示每个帖子的标题和简历?

我正在编辑的网站是:http://thestudentbubble.com/trips-away/

目前我有以下代码:

代码语言:javascript
运行
复制
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
    <div class="featured-post">
        <?php _e( 'Featured post', 'twentytwelve' ); ?>
    </div>
    <?php endif; ?>
    <header class="entry-header">
        <div class="scale"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></div>
        <div class="content-list">
            <h1 class="entry-title">
                <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
            </h1>
            <?php if(!in_category( array( 10,12,13 ) )){ if(function_exists('the_ratings')) { the_ratings(); } } ?>
            <?php // the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?>

                    <div class="decent-comments">
<ul>
    <li>
            <div class="comment">



<?php
$cats = get_the_category();
$category_id = $cats[0]->cat_ID;
$args = array( 'posts_per_page' => 1, 'category' => $category_id);
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) :
  setup_postdata( $post ); ?>

<?php the_content("Continue reading " . the_title('', '', false)); ?>
<?php endforeach; 
 wp_reset_postdata(); ?>


            </div>
        </li>
</ul>
</div>

    <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
        </div>
            <div class="clear"></div>
    </header><!-- .entry-content -->
</article><!-- #post -->
EN

Stack Overflow用户

发布于 2014-05-15 23:37:19

代码语言:javascript
运行
复制
$c = "xfgnx dfbdf dsfbdfb";
$charLimit = 5;
echo strlen ($c);
echo "<br>";
echo substr($c, $charLimit);

这应该会有帮助

票数 1
EN
查看全部 5 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23682639

复制
相关文章

相似问题

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