admin管理员组

文章数量:1122832

Hi I need to display only titles of the posts please help here is my archive.php code

<?php global $theme; get_header(); ?>

<div id="main">

    <?php $theme->hook('main_before'); ?>

    <div id="content">

         <?php $theme->hook('content_before'); ?>

          <h2 class="page-title"><?php

          /* If this is a daily archive */
          if (is_day()) {
               printf( __( 'Daily Archives: <span>%s</span>', 'themater' ), get_the_date() );

          /* If this is a monthly archive */
          } elseif (is_month()) {
              printf( __( 'Monthly Archives: <span>%s</span>', 'themater' ), get_the_date('F Y') );

          /* If this is a yearly archive */
          } elseif (is_year()) {
              printf( __( 'Yearly Archives: <span>%s</span>', 'themater' ), get_the_date('Y') );

          /* If this is a general archive */
          } else {
              _e( 'Blog Archives', 'themater' );
          }
          ?>
          </h2>

        <?php
        if (have_posts()) : while (have_posts()) : the_post();

            /**
            * The default post formatting from the post.php template file will be used.
            * If you want to customize the post formatting for your archive pages:
            *
            * - Create a new file: post-archive.php
            * - Copy/Paste the content of post.php to post-archive.php
            * - Edit and customize the post-archive.php file for your needs.
            *
            * Learn more about the get_template_part() function: 
            */

            get_template_part('post', 'archive');
        endwhile;

        else :
            get_template_part('post', 'noresults');
        endif;

        get_template_part('navigation');
    ?>

    <?php $theme->hook('content_after'); ?>

    </div><!-- #content -->

    <?php get_sidebars(); ?>

    <?php $theme->hook('main_after'); ?>

</div><!-- #main -->

<?php get_footer(); ?>

here is post.php file

<?php global $theme; ?>

<div <?php post_class('post clearfix'); ?> id="post-<?php the_ID(); ?>">

    <div class="postmeta-primary">

        <span class="meta_date"><?php echo get_the_date(); ?></span>
        <span class="meta_categories"><?php the_category(', '); ?></span>

        <?php if(comments_open( get_the_ID() )) { ?>
            <span class="meta_comments"><?php comments_popup_link( __( 'No comments', 'themater' ), __( '1 Comment', 'themater' ), __( '% Comments', 'themater' ) ); ?></span>
        <?php } ?>
    </div>

    <h2 class="title">" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></h2>

    <div class="entry clearfix">

    <?php if(has_post_thumbnail()) { ?>">
        <?php the_post_thumbnail(
            array($theme->get_option('featured_image_width'), $theme->get_option('featured_image_height')),
            array("class" => $theme->get_option('featured_image_position') . " featured_image") ); ?>
    <?php } ?>

    <?php the_content(''); ?>

</div>

<?php if($theme->display('read_more')) { ?>
    <div class="readmore">
        #more-<?php the_ID(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
        <?php $theme->option('read_more'); ?>
    </div>
<?php } ?>

</div><!-- Post ID <?php the_ID(); ?> -->

Hi I need to display only titles of the posts please help here is my archive.php code

<?php global $theme; get_header(); ?>

<div id="main">

    <?php $theme->hook('main_before'); ?>

    <div id="content">

         <?php $theme->hook('content_before'); ?>

          <h2 class="page-title"><?php

          /* If this is a daily archive */
          if (is_day()) {
               printf( __( 'Daily Archives: <span>%s</span>', 'themater' ), get_the_date() );

          /* If this is a monthly archive */
          } elseif (is_month()) {
              printf( __( 'Monthly Archives: <span>%s</span>', 'themater' ), get_the_date('F Y') );

          /* If this is a yearly archive */
          } elseif (is_year()) {
              printf( __( 'Yearly Archives: <span>%s</span>', 'themater' ), get_the_date('Y') );

          /* If this is a general archive */
          } else {
              _e( 'Blog Archives', 'themater' );
          }
          ?>
          </h2>

        <?php
        if (have_posts()) : while (have_posts()) : the_post();

            /**
            * The default post formatting from the post.php template file will be used.
            * If you want to customize the post formatting for your archive pages:
            *
            * - Create a new file: post-archive.php
            * - Copy/Paste the content of post.php to post-archive.php
            * - Edit and customize the post-archive.php file for your needs.
            *
            * Learn more about the get_template_part() function: http://codex.wordpress.org/Function_Reference/get_template_part
            */

            get_template_part('post', 'archive');
        endwhile;

        else :
            get_template_part('post', 'noresults');
        endif;

        get_template_part('navigation');
    ?>

    <?php $theme->hook('content_after'); ?>

    </div><!-- #content -->

    <?php get_sidebars(); ?>

    <?php $theme->hook('main_after'); ?>

</div><!-- #main -->

<?php get_footer(); ?>

here is post.php file

<?php global $theme; ?>

<div <?php post_class('post clearfix'); ?> id="post-<?php the_ID(); ?>">

    <div class="postmeta-primary">

        <span class="meta_date"><?php echo get_the_date(); ?></span>
        <span class="meta_categories"><?php the_category(', '); ?></span>

        <?php if(comments_open( get_the_ID() )) { ?>
            <span class="meta_comments"><?php comments_popup_link( __( 'No comments', 'themater' ), __( '1 Comment', 'themater' ), __( '% Comments', 'themater' ) ); ?></span>
        <?php } ?>
    </div>

    <h2 class="title">" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></h2>

    <div class="entry clearfix">

    <?php if(has_post_thumbnail()) { ?>">
        <?php the_post_thumbnail(
            array($theme->get_option('featured_image_width'), $theme->get_option('featured_image_height')),
            array("class" => $theme->get_option('featured_image_position') . " featured_image") ); ?>
    <?php } ?>

    <?php the_content(''); ?>

</div>

<?php if($theme->display('read_more')) { ?>
    <div class="readmore">
        #more-<?php the_ID(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
        <?php $theme->option('read_more'); ?>
    </div>
<?php } ?>

</div><!-- Post ID <?php the_ID(); ?> -->
Share Improve this question edited Dec 9, 2014 at 8:19 cybmeta 20.6k5 gold badges47 silver badges56 bronze badges asked Dec 9, 2014 at 7:15 Astrael KokebAstrael Kokeb 111 silver badge2 bronze badges 1
  • 1 Please properly format your code. File an edit and make proper use of the WYSIWYG editor. As it stands, your code is totally unreadable. Thank you – Pieter Goosen Commented Dec 9, 2014 at 7:27
Add a comment  | 

1 Answer 1

Reset to default 0

This little piece of code in your post.php displays the title:

 <h2 class="title">" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></h2>

To be more precise, this bit does:

<?php the_title(); ?>

So if you only want the post titles visible in only archive.php. Just replace the line:

get_template_part('post', 'archive');

with:

the_title();

Or, even better. Copy post.php to post-archive.php & remove everything from post-archive.php you don't want.

post-archive.php will look like something like this:

<div <?php post_class('post clearfix'); ?> id="post-<?php the_ID(); ?>">
    <h2 class="title">" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></h2>

</div><!-- Post ID <?php the_ID(); ?> -->

本文标签: How to show only Post titles on category pages