WordPress.org

Support

Support » Themes and Templates » [Resolved] Display only the title in categories

[Resolved] Display only the title in categories

  • agonche

    @agonche

    I am using Twenty Twelve theme.

    When a user clicks on a category, I want the website to show only post titles, not the content (whole post).
    How do I do that ? What to edit ?

Viewing 14 replies - 1 through 14 (of 14 total)
  • Kegan Quimby

    @keganquimby

    If you go to Appearance > Editor and edit the archives.php file, you can pull out the line that says <?php the_content(); ?> or <?php the_excerpt(); ?>

    agonche

    @agonche

    I am using WordPress 3.4.2 and Twenty Twelve theme.
    There isn’t a line that says <?php the_content(); ?> or <?php the_excerpt(); ?>

    Maybe that method works in older versions or different themes.

    Here is my archive.php file.

    <?php
    /**
     * The template for displaying Archive pages.
     *
     * Used to display archive-type pages if nothing more specific matches a query.
     * For example, puts together date-based pages if no date.php file exists.
     *
     * If you'd like to further customize these archive views, you may create a
     * new template file for each specific one. For example, Twenty Twelve already
     * has tag.php for Tag archives, category.php for Category archives, and
     * author.php for Author archives.
     *
     * Learn more: http://codex.wordpress.org/Template_Hierarchy
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    
    get_header(); ?>
    
    	<section id="primary" class="site-content">
    		<div id="content" role="main">
    
    		<?php if ( have_posts() ) : ?>
    			<header class="archive-header">
    				<h1 class="archive-title"><?php
    					if ( is_day() ) :
    						printf( __( 'Daily Archives: %s', 'twentytwelve' ), '<span>' . get_the_date() . '</span>' );
    					elseif ( is_month() ) :
    						printf( __( 'Monthly Archives: %s', 'twentytwelve' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentytwelve' ) ) . '</span>' );
    					elseif ( is_year() ) :
    						printf( __( 'Yearly Archives: %s', 'twentytwelve' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentytwelve' ) ) . '</span>' );
    					else :
    						_e( 'Archives', 'twentytwelve' );
    					endif;
    				?></h1>
    			</header><!-- .archive-header -->
    
    			<?php
    			/* Start the Loop */
    			while ( have_posts() ) : the_content();
    
    				/* Include the post format-specific template for the content. If you want to
    				 * this in a child theme then include a file called called content-___.php
    				 * (where ___ is the post format) and that will be used instead.
    				 */
    				get_template_part( 'content', get_post_format() );
    
    			endwhile;
    
    			twentytwelve_content_nav( 'nav-below' );
    			?>
    
    		<?php else : ?>
    			<?php get_template_part( 'content', 'none' ); ?>
    		<?php endif; ?>
    
    		</div><!-- #content -->
    	</section><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    agonche

    @agonche

    or maybe I should edit the Category Template (category.php) file ?

    esmi

    @esmi

    Forum Moderator

    Do not edit the Twenty Twelve theme. It is will be the default theme in WordPress 3.5 and having access to an unedited version of the theme is vital when dealing with a range of site issues. First create a child theme for your changes.

    agonche

    @agonche

    Okay, thanks for the tip, but you didn’t answer my question
    Anyone else ?

    esmi

    @esmi

    Forum Moderator

    Have you created a child theme yet?

    agonche

    @agonche

    Yes sir.

    esmi

    @esmi

    Forum Moderator

    Create a copy of the parent’s content.php template in the child theme and then edit this copy. Replace:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>

    with:

    <?php if ( is_search() || is_category() ) : ?>

    agonche

    @agonche

    Almost there.
    I want just the title of the post, not the excerpt.

    esmi

    @esmi

    Forum Moderator

    In that case, remove:

    <?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>', 'twentytwelve' ) ); ?>
    			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    		</div><!-- .entry-content -->
    		<?php endif; ?>
    esmi

    @esmi

    Forum Moderator

    Sorry – scratch that. I’m not thinking straight. Replace:

    <?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">&rarr;</span>', 'twentytwelve' ) ); ?>
    <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    </div><!-- .entry-content -->
    <?php endif; ?>

    with:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    <div class="entry-summary">
    <?php the_excerpt(); ?>
    </div><!-- .entry-summary -->
    <?php elseif( !is_category() ) : ?>
    <div class="entry-content">
    <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?>
    <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
    </div><!-- .entry-content -->
    <?php endif; ?>

    This worked for me, thanks.

    Hi
    I am using a grid like structure for my front page.It will show only th featured images of the posts. I need only its category tile to be displayed on the top of the image. How to do it?

    WPyogi

    @wpyogi

    Forum Moderator

    @dhanyaabraham – please start your own thread and include more info in your post –

    http://codex.wordpress.org/Forum_Welcome#Where_To_Post

    http://codex.wordpress.org/Forum_Welcome#Include_as_much_information_as_possible

    This thread is marked resolved and quite out of date.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Resolved] Display only the title in categories’ is closed to new replies.
Skip to toolbar