Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

I'd like posts abbreviated and comments not-showing on home page? WordPress

  • SOLVED

My site is LivingByFaithBlog.com

Right now my home page lists each post in full along with comments.

But I'd like the home page to show an abbreviated version of each post, and not show the comments -- but give readers an option to "read more."

I'm using the Grid Focus theme.

I'd prefer to make the code changes myself, if at all possible, so I can learn.

Thanks.

Steve Fuller

Answers (3)

2011-12-19

Navjot Singh answers:

Can you post the full code from your theme's index.php here?


SteveFuller comments:

Here you go --

<?php
/**
* @package WordPress
* @subpackage Grid_Focus
*/
get_header();
?>
<div id="filler" class="fix">
<div id="mainColumn">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="post">
<div class="postMeta">
<p class="container">
<span class="date"><?php the_time('M j, Y') ?></span>
<span class="comments"><?php comments_popup_link('0', '1', '%'); ?></span>
</p>
</div>
<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title() ?></a></h2>
<div class="entry">
<?php the_content('Read the rest of this entry &raquo;'); ?>
</div>
</div>
<?php $withcomments = 1; ?>
<?php comments_template(); ?>
<?php endwhile; ?>
<?php else : ?>
<div class="post">
<div class="postMeta">
<p class="container">
<span class="date">No Matches</span>
</p>
</div>
<h2>No matching results</h2>
<div class="entry">
<p>You seem to have found a mis-linked page or search query with no matching results. Please trying your search again. If you feel that you should be staring at something a little more concrete, feel free to email the author of this site or browse the archives.</p>
</div>
</div>
<?php endif; ?>
<div id="paginateIndex" class="fix">
<p><span class="left"><?php previous_posts_link('&laquo; Previous') ?></span> <span class="right"><?php next_posts_link('Next &raquo;') ?></span></p>
</div>
</div>
<?php include (TEMPLATEPATH . '/second.column.post.php'); ?>
<?php include (TEMPLATEPATH . '/third.column.shared.php'); ?>
</div>


Navjot Singh comments:

Remove these 2 lines:

<?php $withcomments = 1; ?>
<?php comments_template(); ?>


and replace this line

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

with

<?php the_excerpt(); ?>


SteveFuller comments:

That helps.

Is there any way to have a "read more" button at the bottom of each excerpt?


Navjot Singh comments:

Add this code in your functions.php

function new_excerpt_more($more) {
global $post;
return '<a href="'. get_permalink($post->ID) . '">Read More...</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');


for that. This will add read more text with a link to the full post.


SteveFuller comments:

And is there any way to keep the pictures along with the excerpt?


Navjot Singh comments:

Install [[LINK href="http://wordpress.org/extend/plugins/get-the-image/"]]this plugin[[/LINK]] and add this code

<?php if ( function_exists( 'get_the_image' ) ) get_the_image(); ?>

after this line

<div class="entry">


SteveFuller comments:

To add the code for "read more" to the functions.php --

Where should I add it?

Is location important?


Navjot Singh comments:

Just add before the last ?> in the file to be on the safe side. Location is important so that the code doesn't go inside any other function or loop. So always add such code snippets before the last appearing ?>.


SteveFuller comments:

The "read more" worked -- but is there any way to have a space between it and the last letter of the excerpt -- or even to have it show up by itself in the following line.


SteveFuller comments:

And back to the image question

Into which php file do I add that code?

I will try that in a few hours -- need to run to an appointment now.

You've been very helpful so far. Thank you.


SteveFuller comments:

Also -- concerning the image code addition to index.php

There's 2 <div class="entry"> lines in index.php

After which one do I add the line of code --

<?php if ( function_exists( 'get_the_image' ) ) get_the_image(); ?>


Navjot Singh comments:

To show the read more line in its own line change

return '<a href="'. get_permalink($post->ID) . '">Read More...</a>';

to

return '<p><a href="'. get_permalink($post->ID) . '">Read More...</a></p>';

And add that image code below first <div class="entry"> just above the <?php the_excerpt(); ?> in your index.php.




SteveFuller comments:

The "add image" change worked.

But the text does not start until below the image -- any chance it could start next to the image?

You have been very helpful. Thank you.


Navjot Singh comments:

To do that instead of adding

<?php if ( function_exists( 'get_the_image' ) ) get_the_image(); ?>

add this line

<?php if ( function_exists( 'get_the_image' ) ) get_the_image( array( 'image_class' => 'alignleft' ) ); ?>


SteveFuller comments:

Very good. Thank you. I am going to vote you the money.

If it's not too much trouble -- is there an easy way to remove the Share / Tweet / Share / Google_+ buttons from each entry on the home page -- but still have them show up if someone looks at the individual post on it's own page?

2011-12-19

Julio Potier answers:

Hello

You can replace the "the_content()" by "the_excerpt()" in your home.php template.

Hope it helps !


SteveFuller comments:

Thanks. That did shorten the blog post.

But it also removed the pictures, and left the comments.

Any other ideas?


Julio Potier comments:

Ho sorry, for comments you have to search a "comment_form()" or come like this and remove (or comment) it.

For pictures, yep ... the excerpt is ... an excerpt ! If pictures are into the post, you can grab the 1st post image with this function :

function my_first_image() {
global $post;
$img = '';
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
if ( isset($matches[1][0]) ) $img = $matches[1][0];

return trim($img);
}


Then use is like this for example :
<?php
echo my_first_image();
the_excerpt();
?>


See you !

2011-12-19

Linda answers:

Hi, just as Julio says change


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


into


<?php the_excerpt('Read more'); ?>