Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following blog template with the the_content outputted. I have placed <!--more-->

However it does not appear to be functioning,

http://www.milknhny.co.uk/DVine/?page_id=19

Is there anything that needs to be included within functions for this to function?

Code Of my Blog Template

<?php
/*
Template Name: Blog Template
*/
 ?>

<?php get_header();?>
<?php echo get_the_post_thumbnail($post->ID, 'single-post-thumbnail'); ?>
<div id="maincontentwrap" role="main">
<?php query_posts('showposts=5'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 <div class="datebackground"><span class="day"><?php echo get_the_date('j'); ?></span>    <span class="month"><?php echo get_the_date('M'); ?></span></div>
<div class="postsh1"><?php echo get_the_title(); ?></div>
<div id="blogwrapper">
Written by <?php the_author_posts_link() ?> in <?php the_category(); ?>
<?php the_content('read more...'); ?>

<br>
<div class="pagedivider"></div>
</div>  
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div><!-- #content -->
<?php get_footer(); ?>

EDIT

I have found this within the Twenty Twelve theme and ive tried to adapt this to my own however the - errors the actual code...

function DTheme_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'DTheme_excerpt_length' );

if ( ! function_exists( 'DTheme_continue_reading_link' ) ) :
/**
 * Returns a "Continue Reading" link for excerpts
 *
 * @since Twenty Ten 1.0
 * @return string "Continue Reading" link
 */
function DTheme_continue_reading_link() {
return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-  nav">&rarr;</span>', 'DTheme' ) . '</a>';
}
endif;

/**
 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
 *
 * To override this in a child theme, remove the filter and add your own
 * function tied to the excerpt_more filter hook.
 *
 * @since Twenty Ten 1.0
 * @return string An ellipsis
 */
function DTheme_auto_excerpt_more( $more ) {
return ' &hellip;' . DTheme_continue_reading_link();
}
add_filter( 'excerpt_more', 'DTheme_auto_excerpt_more' );
?>

Is it a case i would need to adapt the above for this to work?

EDIT

Hi all, this appears to be part working after amazing help below, however it is still not displaying within the content wrap and also images for example are resizing... please see my code now and also screenshot

<?php get_header(); ?>
<div id="maincontentwrap" role="main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="datebackground"><span class="day"><?php echo get_the_date('j'); ?></span>    <span class="month"><?php echo get_the_date('M'); ?></span></div>
<div class="postsh1"><?php echo get_the_title(); ?></div>
<div id="blogwrapper">
Written by <?php the_author_posts_link() ?> in <?php the_category(); ?>
<?php the_content(); ?>

 <br>
<div class="pagedivider"></div>
</div>  
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div><!-- #content -->
<?php get_footer(); ?>

Screenshot of further info on click

share|improve this question
    
Post your code please. –  s_ha_dum Dec 19 '12 at 18:51
    
One: why are you using a "blog" template, instead of using the Template Hierarchy-specified home.php? Two: what do you have set in Settings -> Reading as Posts Page? Three: why are you calling query_posts() in your template? –  Chip Bennett Dec 19 '12 at 20:53
1  
Also: please add <?php body_class(); ?> to your HTML <body> tag, like so: <body <?php body_class(); ?>>. It is crucial to debugging template issues. –  Chip Bennett Dec 19 '12 at 20:54
    
Hi Chip, please can i chat to you reference this, as im unsure of a few points. –  Kirsty Harris Dec 19 '12 at 20:55
    
I used the query posts function as i didnt want to overload the page, so i just wanted to show the last 5 posts so to speak, I do have it as show posts. As for the home.php, please can i have the link to this, as i wasnt aware that i had to use the home.php as the blog main template. Actually ive found the home.php... –  Kirsty Harris Dec 19 '12 at 20:59
show 2 more comments

1 Answer

up vote 2 down vote accepted

I see several things that may be contributing to your issue.

First, you're using a custom page template to display the blog posts index, instead of using home.php as specified by the Template Hierarchy. That might be a problem, because the <!--more--> tag doesn't work on singular pages, and since you're doing funky things with the default query (more on that below), The global $more on which <!--more--> relies might not be getting set as you expect it to be.

Proper configuration of static page as blog posts index

So, the first step is to set up a proper configuration for a static page as blog posts index:

  1. Ensure your chosen static page is selected as Posts Page in Dashboard -> Settings -> Reading
  2. Rename your custom page template as home.php
  3. Remove the Template Name: Blog Template tag from the phpDoc header
  4. (Assumed: you have a static page already selected as Front Page)

Don't stomp on the main query

If that alone doesn't resolve your problem, then the next issue to investigate is the way you're stomping on the default query with query_posts(). Do not ever use query_posts(), for anything, ever.

If you want to set your blog posts index to display a given number of posts, then filter the $query via pre_get_posts, like so:

function wpse76634_filter_pre_get_posts( $query ) {
    if ( is_home() && $query->is_main_query() ) {
        $query->set( 'posts_per_page', '5' );
    }
}
add_action( 'pre_get_posts', 'wpse76634_filter_pre_get_posts' );

Then, get rid of your call to query_posts() in the template file.

Proper usage of <!--more-->

If that doesn't resolve your problem, then the next step is to check your usage of the <!--more--> tag itself.

Ensure that the tag is exactly <!--more-->, with no spaces between <!-- and more or between more and -->.

Issues Outside the Template

If that still doesn't resolve your problem, you may have code somewhere, either in functions.php or in a Plugin, that is altering the functionality of the <!--more--> tag.

To test for a Plugin-related issue, deactivate all Plugins, and switch to the default Theme (currently: Twenty Twelve) and verify whether the <!--more--> tag works properly. If it then works properly, re-enable your Plugins one-by-one. If the <!--more--> tag still works properly with all Plugins active, then the problem is somewhere in your Theme.

The next step is to rule out your template file. If you've followed the steps above, rename home.php as home.php.old, so that WordPress falls back to index.php to render the Blog Posts Index. Then, verify whether the <!--more--> tag works properly.

If it does, then the problem is your template. If it doesn't, then the problem is somewhere in functions.php.

share|improve this answer
    
Hi Chip, thankyou for the very detailed discussion. I will try all the above. I havent got anything however in my functions file, will that be an issue seeming that the Twenty Eleven has extra bits reference the excerpt in there. The fact is that i never had a home.php file in the first place and neither from what i can see does the above theme, so with that im assuming the the Twenty Eleven function is refering back to the index.php file? Sorry im just trying to understand. Also there are loads of tutorials using the query post above... is it wrong?? –  Kirsty Harris Dec 19 '12 at 21:50
    
Also the above seems to be focussing on the home page, i really dont want the home page to be my blog, i want it to be a static one. Surely if i have no home.php then it should be falling back to index... if thats the case am i missing something like a function for the excerpt in my functions file? Sorry for all the questions –  Kirsty Harris Dec 19 '12 at 22:09
    
Hi Chip you are a god! It worked, however quick one it appears that the content is not fully displaying, where does it redirect to?,... shall i post the full "home.php"... thankyou again :) Also the picture that i had in there has resorted back to a huge size when i specified its height.. i can send you a screen shot?... please see update for what it looks like :) –  Kirsty Harris Dec 19 '12 at 22:25
    
Kirsty: the home.php template file is not used to render the Site Front Page. It is used to render the Blog Posts Index (whether or not the Blog Posts Index is on the site front page). In WordPress parlance, home refers to the Blog Posts Index, not to the Site Front Page. –  Chip Bennett Dec 19 '12 at 23:37
    
"however it is still not displaying within the content wrap and also images for example are resizing" - that is an issue unrelated to your original question; as such, I would recommend posting it as a new, separate question. –  Chip Bennett Dec 19 '12 at 23:38
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.