• Resolved joy090394

    (@joy090394)


    Hi, I am currently using Suits theme for my blog. This theme only shows excerpts for the search page. I want excerpts to show on the front page of my blog too.

    My content.php looks like this:

    <?php
    /**
     * The default template for displaying content. Used for both single and index/archive/search.
     *
     * @package Suits
     * @since Suits 1.0
     */
    ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<header class="entry-header">
    		<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
    		<div class="entry-thumbnail">
    			<?php the_post_thumbnail(); ?>
    		</div>
    		<?php endif; ?>
    
    		<?php if ( is_single() ) : ?>
    		<h1 class="entry-title"><?php the_title(); ?></h1>
    		<?php else : ?>
    		<h1 class="entry-title">
    			<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
    		</h1>
    		<?php endif; // is_single() ?>
    	</header><!-- .entry-header -->
    
    	<?php if ( is_search() ) : // Only display Excerpts for Search ?>
    	<div class="entry-summary">
    		<?php the_excerpt(); ?>
    	</div><!-- .entry-summary -->
    	<?php else : ?>
    	<div class="entry-content">
    		<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'suits' ) ); ?>
    		<?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'suits' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
    	</div><!-- .entry-content -->
    	<?php endif; ?>
    
    	<footer class="entry-meta">
    		<?php suits_entry_meta(); ?>
    		<?php if ( comments_open() ) : ?>
    			<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a comment', 'suits' ) . '</span>', __( '1 Comment', 'suits' ), __( '% Comments', 'suits' ) ); ?>
    		<?php endif; // comments_open() ?>
    		<?php edit_post_link( __( 'Edit', 'suits' ), '<span class="edit-link">', '</span>' ); ?>
    	</footer><!-- .entry-meta -->
    </article><!-- #post -->

    I tried editing <?php the_content> to <?php the_excerpt>, and the front page will show the excerpt, but when I click to view a particular post, it will show the excerpt only (not the full post).

    Also, I want to include a <read more> link after the excerpt of each post. Can someone help me to suggest edits to these codes? Thanks so much! 😀

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello joy090394,

    You’re halfway there! As you mentioned changing <?php the_content> to <?php the_excerpt> shows the excerpt, this is exactly what you need. Your issue is you’re editing the template that is used for the single page.

    You should copy your content.php and rename the copy to something like home-content.php and reference this in your homepage template (If you are using a custom homepage template, I’m unsure of your setup). You can then make your excerpt change to the home-content.php file.

    Hope that’s somewhat helpful!

    Thread Starter joy090394

    (@joy090394)

    Arh I see. I think my content-page.php links to the front page and the individual post when I click on it. I reckon that Page.php should be my homepage template since it displays all pages like this:

    <?php
    /**
     * The template for displaying all pages.
     *
     * This is the template that displays all pages by default.
     * Please note that this is the WordPress construct of pages and that other
     * 'pages' on your WordPress site will use a different template.
     *
     * @package Suits
     * @since Suits 1.0
     */
    
    get_header(); ?>
    
    	<div id="primary" class="content-area">
    		<div id="content" class="site-content" role="main">
    
    			<?php /* The loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    				<?php get_template_part( 'content', 'page' ); ?>
    				<?php comments_template(); ?>
    			<?php endwhile; ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    How do I rename a php file? My website is thesolidfood.org/youth. Maybe you can help me take a look and suggest edits?

    Also, so sorry cos this is the first time I’m working with php files. I’m still trying to get the hang of it haha 😀

    Alternatively, change the condition in your content.php to:

    <?php if ( is_search() || is_front_page()) : // Only display Excerpts for Search ?>
    	<div class="entry-summary">
    		<?php the_excerpt(); ?>
    	</div><!-- .entry-summary -->
    	<?php else : ?>
    	<div class="entry-content">
    		<?php the_content(); ?>

    Note that the change is only in the first line. We have added another condition to the if-clause

    Thread Starter joy090394

    (@joy090394)

    Thanks so much graphicscove & shariqkhan2012 — the codes worked perfectly fine on my site 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to show excepts in front page of site’ is closed to new replies.