• Hi all,

    Back again as so far the help on here has been excellent!

    I have a Twenty Twelve Child theme, and tweaking as I go. I noticed that I had an issue with full posts being displayed on the blog roll which I sorted by following a similar post. However I have several custom pages that currently only display posts from certain categories, this is working fine however the full post is being displayed on these as well. I want the excerpt to be displayed and then the user can link to read more.

    I created these custom pages by copying the index.php, and think I need to edit this piece of code but unsure how.

    <?php query_posts('category_name=MSP430'); ?>
    		<?php if ( have_posts() ) : ?>
    
    			<?php /* Start the Loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    				<?php get_template_part( 'content', get_post_format() ); ?>
    			<?php endwhile; ?>
    
    			<?php twentytwelve_content_nav( 'nav-below' ); ?>
    
    		<?php else : ?>

    The main blog roll for the site can be seen here
    https://coder-tronics.com/news/

    And one of the custom pages can be seen here with the issue
    https://coder-tronics.com/articles/msp430/

    Thanks,

    Ant

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Antscran

    (@antscran)

    I managed to implement this by using a custom content.php file, basically created a copy of the content.php with a few minor edits and placed in my child theme folder calling it custom-contenet.php (as only wanted to use it for certain pages). Then using the code in my first post I substituted this line

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

    and placed this is my template.php files that I wanted to display excerpts, which in my case is most of my pages and even archive.php. You can find the line of code to change quite easily in these files as has exactly the same format.

    <?php get_template_part( 'custom-content', get_post_format() ); ?>

    The custom-content.php file can be seen below, as I mentioned it’s basically almost the same as the content.php file, but just edited so it only displays excerpts.

    <?php
    /**
     * The default template for displaying content. Used for both single and index/archive/search.
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    ?>
    
    	<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">
    			<?php the_post_thumbnail(); ?>
    			<?php if ( is_single() ) : ?>
    			<h1 class="entry-title"><?php the_title(); ?></h1>
    			<?php else : ?>
    			<h1 class="entry-title">
    				<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
    			</h1>
    			<?php endif; // is_single() ?>
    			<?php if ( comments_open() ) : ?>
    				<div class="comments-link">
    
    				<!-- ** Commented out "leave reply" code as not required -->
    				<?php /* comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); */ ?>
    				</div><!-- .comments-link -->
    			<?php endif; // comments_open() ?>
    		</header><!-- .entry-header -->
    
    		<!-- ** Removed if is_search so excerpt is displayed for all custom portfolio posts -->
    		<div class="entry-summary">
    			<?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->
    
    		<footer class="entry-meta">
    			<?php twentytwelve_entry_meta(); ?>
    			<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
    			<?php if ( is_singular() && get_the_author_meta( 'description' ) && is_multi_author() ) : // If a user has filled out their description and this is a multi-author blog, show a bio on their entries. ?>
    				<div class="author-info">
    					<div class="author-avatar">
    						<?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentytwelve_author_bio_avatar_size', 68 ) ); ?>
    					</div><!-- .author-avatar -->
    					<div class="author-description">
    						<h2><?php printf( __( 'About %s', 'twentytwelve' ), get_the_author() ); ?></h2>
    						<p><?php the_author_meta( 'description' ); ?></p>
    						<div class="author-link">
    							<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
    								<?php printf( __( 'View all posts by %s <span class="meta-nav">→</span>', 'twentytwelve' ), get_the_author() ); ?>
    							</a>
    						</div><!-- .author-link	-->
    					</div><!-- .author-description -->
    				</div><!-- .author-info -->
    			<?php endif; ?>
    		</footer><!-- .entry-meta -->
    	</article><!-- #post -->

    Hope this helps somebody else!

    Cheers,

    Ant

    Audee

    (@graphicidentity)

    Just what I’ve been looking for! after hours of searching for solution ??
    Thank you so much for sharing this nice trick!

    Audee

    (@graphicidentity)

    Btw, just want to let you know that it did display the excerpt, but I lost the post format styling.
    It works if I use content.php only and included this:

    `<?php if ( is_search()|| is_category() ) : ?>
    <?php the_excerpt(); ?>

    <?php else : ?>
    <?php the_content(); ?>
    <?php endif; ?>`

    to replace:

    <?php the_content(); ?>

    Thread Starter Antscran

    (@antscran)

    Glad it helped maybe not exactly as expected, but sure your feedback will help someone else as well.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Twenty Twelve Custom page to display excerpt’ is closed to new replies.