Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

I know this is normally an obvious question with a lot of answers (like herehere), but I'd like to show only the beginning of the posts with a "read more" button. I don't use excerpts, so I'd like Wordpress to automaticly grab the first 55 words or the first phrase to display it.

I use the theme Toivo Lite. The index.php is:

<?php
get_header(); ?>

<?php if ( have_posts() ) : ?>
    
    <?php do_action( 'toivo_before_loop' ); // Action hook before loop. ?>

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>

        <?php
            /* Include the Post-Format-specific template for the content.
             * If you want to override this in a child theme, then include a file
             * called content-___.php (where ___ is the Post Format name) and that will be used instead.
             */
            get_template_part( 'content', ( post_type_supports( get_post_type(), 'post-formats' ) ? get_post_format() : get_post_type() ) );
        ?>

    <?php endwhile; ?>
        
    <?php
        the_posts_pagination( array(
            'prev_text'          => __( 'Previous page', 'toivo-lite' ),
            'next_text'          => __( 'Next page', 'toivo-lite' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'toivo-lite' ) . ' </span>',
        ) );
    ?>

<?php else : ?>

    <?php get_template_part( 'content', 'none' ); ?>

<?php endif; ?>
    
<?php do_action( 'toivo_after_loop' ); // Action hook after loop. ?>

<?php get_footer(); ?>

I've tried to replace the two content by excerpt, but then the page is empty (only header and foot).

I know this is normally an obvious question with a lot of answers (like here), but I'd like to show only the beginning of the posts with a "read more" button. I don't use excerpts, so I'd like Wordpress to automaticly grab the first 55 words or the first phrase to display it.

I use the theme Toivo Lite. The index.php is:

<?php
get_header(); ?>

<?php if ( have_posts() ) : ?>
    
    <?php do_action( 'toivo_before_loop' ); // Action hook before loop. ?>

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>

        <?php
            /* Include the Post-Format-specific template for the content.
             * If you want to override this in a child theme, then include a file
             * called content-___.php (where ___ is the Post Format name) and that will be used instead.
             */
            get_template_part( 'content', ( post_type_supports( get_post_type(), 'post-formats' ) ? get_post_format() : get_post_type() ) );
        ?>

    <?php endwhile; ?>
        
    <?php
        the_posts_pagination( array(
            'prev_text'          => __( 'Previous page', 'toivo-lite' ),
            'next_text'          => __( 'Next page', 'toivo-lite' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'toivo-lite' ) . ' </span>',
        ) );
    ?>

<?php else : ?>

    <?php get_template_part( 'content', 'none' ); ?>

<?php endif; ?>
    
<?php do_action( 'toivo_after_loop' ); // Action hook after loop. ?>

<?php get_footer(); ?>

I've tried to replace the two content by excerpt, but then the page is empty (only header and foot).

I know this is normally an obvious question with a lot of answers (like here), but I'd like to show only the beginning of the posts with a "read more" button. I don't use excerpts, so I'd like Wordpress to automaticly grab the first 55 words or the first phrase to display it.

I use the theme Toivo Lite. The index.php is:

<?php
get_header(); ?>

<?php if ( have_posts() ) : ?>
    
    <?php do_action( 'toivo_before_loop' ); // Action hook before loop. ?>

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>

        <?php
            /* Include the Post-Format-specific template for the content.
             * If you want to override this in a child theme, then include a file
             * called content-___.php (where ___ is the Post Format name) and that will be used instead.
             */
            get_template_part( 'content', ( post_type_supports( get_post_type(), 'post-formats' ) ? get_post_format() : get_post_type() ) );
        ?>

    <?php endwhile; ?>
        
    <?php
        the_posts_pagination( array(
            'prev_text'          => __( 'Previous page', 'toivo-lite' ),
            'next_text'          => __( 'Next page', 'toivo-lite' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'toivo-lite' ) . ' </span>',
        ) );
    ?>

<?php else : ?>

    <?php get_template_part( 'content', 'none' ); ?>

<?php endif; ?>
    
<?php do_action( 'toivo_after_loop' ); // Action hook after loop. ?>

<?php get_footer(); ?>

I've tried to replace the two content by excerpt, but then the page is empty (only header and foot).

Source Link
Shan-x
  • 109
  • 1

Show only the beginning of post

I know this is normally an obvious question with a lot of answers (like here), but I'd like to show only the beginning of the posts with a "read more" button. I don't use excerpts, so I'd like Wordpress to automaticly grab the first 55 words or the first phrase to display it.

I use the theme Toivo Lite. The index.php is:

<?php
get_header(); ?>

<?php if ( have_posts() ) : ?>
    
    <?php do_action( 'toivo_before_loop' ); // Action hook before loop. ?>

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>

        <?php
            /* Include the Post-Format-specific template for the content.
             * If you want to override this in a child theme, then include a file
             * called content-___.php (where ___ is the Post Format name) and that will be used instead.
             */
            get_template_part( 'content', ( post_type_supports( get_post_type(), 'post-formats' ) ? get_post_format() : get_post_type() ) );
        ?>

    <?php endwhile; ?>
        
    <?php
        the_posts_pagination( array(
            'prev_text'          => __( 'Previous page', 'toivo-lite' ),
            'next_text'          => __( 'Next page', 'toivo-lite' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'toivo-lite' ) . ' </span>',
        ) );
    ?>

<?php else : ?>

    <?php get_template_part( 'content', 'none' ); ?>

<?php endif; ?>
    
<?php do_action( 'toivo_after_loop' ); // Action hook after loop. ?>

<?php get_footer(); ?>

I've tried to replace the two content by excerpt, but then the page is empty (only header and foot).