This most likely has a very simple solution. I am building a blog using the Ixion theme. I really like the layout so far, and I'm almost ready to publish. However, the theme is designed to only display post name, post date, and post categories on the front page. I would like to additionally include the post excerpt. I have found the code that is responsible for populating the list of the most recent posts on the home page (taken from index.php):
while ( have_posts() ) : the_post();
/*
* 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( 'components/post/content', get_post_format() );
endwhile;
The following code then formats each post, found in components/post/content.php:
<?php
/**
* Template part for displaying posts.
*
* @link
*
* @package Ixion
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-body">
<header class="entry-header">
<?php
if ( has_post_thumbnail() && ! is_single() ) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'ixion-featured-image' ); ?>
</a>
</div>
<?php
endif;
if ( ! is_single() ) {
if ( 'post' === get_post_type() ) {
get_template_part( 'components/post/content', 'meta' );
}
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
}
?>
</header>
<div class="entry-content">
<?php
the_content( sprintf(
/* translators: %s: Name of current post. */
wp_kses( __( 'Continue reading %s <span class="meta-nav">→</span>', 'ixion' ), array( 'span' => array( 'class' => array() ) ) ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
) );
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'ixion' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<?php if ( is_single() ) {
get_template_part( 'components/post/content', 'footer' );
} ?>
<?php if ( 'post' === get_post_type() ) {
ixion_author_bio();
} ?>
</div> <!-- .entry-body -->
Specifically, I have identified the function call that is responsible for populating the information for each post, and it is:
the_content( sprintf(
/* translators: %s: Name of current post. */
wp_kses( __( 'Continue reading %s <span class="meta-nav">→</span>', 'ixion' ), array( 'span' => array( 'class' => array() ) ) ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
) );
How can I modify this function to include an excerpt from the blog post? I am neither a PHP nor WordPress developer, so I've definitely missed some things between.
Thanks!
This most likely has a very simple solution. I am building a blog using the Ixion theme. I really like the layout so far, and I'm almost ready to publish. However, the theme is designed to only display post name, post date, and post categories on the front page. I would like to additionally include the post excerpt. I have found the code that is responsible for populating the list of the most recent posts on the home page (taken from index.php):
while ( have_posts() ) : the_post();
/*
* 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( 'components/post/content', get_post_format() );
endwhile;
The following code then formats each post, found in components/post/content.php:
<?php
/**
* Template part for displaying posts.
*
* @link https://codex.wordpress/Template_Hierarchy
*
* @package Ixion
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-body">
<header class="entry-header">
<?php
if ( has_post_thumbnail() && ! is_single() ) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'ixion-featured-image' ); ?>
</a>
</div>
<?php
endif;
if ( ! is_single() ) {
if ( 'post' === get_post_type() ) {
get_template_part( 'components/post/content', 'meta' );
}
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
}
?>
</header>
<div class="entry-content">
<?php
the_content( sprintf(
/* translators: %s: Name of current post. */
wp_kses( __( 'Continue reading %s <span class="meta-nav">→</span>', 'ixion' ), array( 'span' => array( 'class' => array() ) ) ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
) );
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'ixion' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<?php if ( is_single() ) {
get_template_part( 'components/post/content', 'footer' );
} ?>
<?php if ( 'post' === get_post_type() ) {
ixion_author_bio();
} ?>
</div> <!-- .entry-body -->
Specifically, I have identified the function call that is responsible for populating the information for each post, and it is:
the_content( sprintf(
/* translators: %s: Name of current post. */
wp_kses( __( 'Continue reading %s <span class="meta-nav">→</span>', 'ixion' ), array( 'span' => array( 'class' => array() ) ) ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
) );
How can I modify this function to include an excerpt from the blog post? I am neither a PHP nor WordPress developer, so I've definitely missed some things between.
Thanks!
Share Improve this question asked Dec 30, 2016 at 22:16 David WidenDavid Widen 11 Answer
Reset to default 0The simplest solution would be to add the_excerpt();
immediately following the title the_title()
tag.
There may be some other mods to make, but the_excerpt()
is what you're after.