WordPress.org

Ready to get started?Download WordPress

Forums

Full post permalink, short post category (14 posts)

  1. bylto
    Member
    Posted 7 years ago #

    Hi, maybe someone could help me. What I would like is the full post to appear at 'home' and the permalink but in 'categories' and 'January, February etc.' just a short snippet, like the first 50-100 words. I don't want a plugin that turns all posts into snippets no matter where they appear. Does anyone know how to do this?

    Thanks everyone

  2. Trent Adams
    Member
    Posted 7 years ago #

    You need to edit your theme (whether it is archive.php or something to do with archives) and change the post being called from the_post to the_excerpt. Here is example of mine:

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

    Change to:

    <?php while (have_posts()) : the_excerpt(); ?>

    That should do it!

    Trent

  3. bylto
    Member
    Posted 7 years ago #

    Thanks very much Trent!

  4. Kafkaesqui

    Posted 7 years ago #

    Actually, Trent's suggestion should have gone more like:

    <?php while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>

    Change to:

    <?php while (have_posts()) : the_post(); ?>
    <?php the_excerpt(); ?>

    the_content() is what outputs the content of a post, and is what you want to swap out here.

  5. Trent Adams
    Member
    Posted 7 years ago #

    Thanks for clarifying Kaf.

    Trent

  6. bylto
    Member
    Posted 7 years ago #

    Thanks guys gonna give that a try now

  7. bylto
    Member
    Posted 7 years ago #

    Actually, when I go to theme editor, these are the only files available to edit

    * Stylesheet
    * Footer
    * Comments
    * functions.php
    * Header
    * Main Index Template
    * Page Template
    * Sidebar

    I tried page template but that makes the Pages excerpts. What should I edit?

  8. Kafkaesqui

    Posted 7 years ago #

    In your "Main Index Template" (index.php), change the line for the_content() to the following:

    <?php if( is_home() || is_single() ) {
    the_content();
    } else {
    the_excerpt();
    } ?>

    More info:
    http://codex.wordpress.org/Conditional_Tags

  9. bylto
    Member
    Posted 7 years ago #

    Hi Kafkaesqui, thanks for all your help. I tried that but there is no code like that in my index.php file. I looked for 'categories' or 'archives' in this file and they are not there either. I also checked out that link and it recommends things that don't seem to appear on my index.php file. I copied the whole file below so you could see it for yourself. If you have time, maybeyou could look over it. Thanks

    <?php get_header(); ?>

    <div id="middle">
    <div id="content">

    <?php if (have_posts()) : ?>

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

    <div class="post" id="post-<?php the_ID(); ?>">

    <h2>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h2>

    <div class="entry">

    <p><?php the_time('F jS, Y') ?> by <?php the_author() ?></p>

    <?php the_content('Read the rest of this entry »'); ?>

    </div>

    <ul class="post-data">
    <li class="comments">
    <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>

    <li class="posted">
    Posted in <?php the_category(', ') ?> <?php edit_post_link('Edit','',''); ?>

    </div>

    <?php comments_template(); ?>

    <?php endwhile; ?>

    <p align="center"><?php next_posts_link('« Previous Entries') ?> <?php previous_posts_link('Next Entries »') ?></p>

    <?php else : ?>

    <h2 align="center">Not Found</h2>

    <p align="center">Sorry, but you are looking for something that isn't here.</p>

    <?php endif; ?>

    </div>
    <?php get_sidebar(); ?>

    </div>

    <?php get_footer(); ?>

  10. bylto
    Member
    Posted 7 years ago #

    Sorry to bump this guys but it got lost a few pages down. Could someone have a look at the code above and maybe let me know how I could have the 'categories' and 'archive' posts as snippets. I would like the home page and permalinks to show the full-length article. Thanks in advance.

  11. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    First, copy that index.php to archive.php. This will make your changes only take effect on archive pages (like dates, categories, etc).

    Then edit the archive.php file and change this:
    <?php the_content('Read the rest of this entry »'); ?>

    to this:
    <?php the_excerpt('Read the rest of this entry »'); ?>

  12. bylto
    Member
    Posted 7 years ago #

    That's the thing Otto, I don't have an archive.php or a categories.php. Should I create these files using the code from index.php and make the relevant changes?

  13. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    bylto: Like I said before: "First, copy that index.php to archive.php".

    The above post I made contains exactly what you need to do. Please read it.

  14. Kafkaesqui

    Posted 7 years ago #

    Or, just make the change in the template from this:

    <?php the_content('Read the rest of this entry »'); ?>

    to this:

    <?php if( is_home() || is_single() ) {
    the_content('Read the rest of this entry »');
    } else {
    the_excerpt();
    } ?>

    I suggested you change the code, hence the reason there is no code in your templates like what I suggested changing it to.

Topic Closed

This topic has been closed to new replies.

About this Topic