Support » Fixing WordPress » <!–more–> fails when index loads from template

  • Resolved JohnP


    I want a static front page, so am loading index.php from within a blog template as described in the codex:

    Template Name: Blog

    <?php query_posts('cat=-0'); //gets all posts
    load_template( TEMPLATEPATH . '/index.php'); //loads index

    I have not set the static home page yet.

    When I look at index.php directly it displays as expected – items stop at “more”.

    But when I load the blog.php page I get the complete text of every post. How can I prevent this?

Viewing 15 replies - 1 through 15 (of 18 total)
  • What is “blog.php”? That’s not a filename that WP would recognize as valid template file.

    The codex says:

    Next, create a blog template. The easiest way to do this is to create a file named blog.php with the following contents in your theme directory:

    Sorry, the second sentence in my question should read:

    But when I load the page…

    I have this problem to. Wasted a lot of time on it.

    The tag shows up in the code of as:

    <p><a id="more-4"></a></p>

    To elaborate, I’ve tried this in different ways using different query methods on the loop. So long as the post with the <!–more–> tag sits within a WordPress default page it works.

    Whenever it’s called from a template page, it doesn’t. I’ve tried copying the whole of the index page to a template page, and of course naming the template page appropriately, but no go. I’ve tried rewind_posts();, specific query_posts and all sorts of things without success.

    If there’s no direct answer can someone please provide a potential line of reasoning – thanks!

    It’s because probably, by design, WP displays full content in Single Post view and Page view–your case.

    So is this correct?

    If you use WordPress as a CMS and need to have a WP-editable static homepage, you will never be able to see the normal blog front page, and the <!– more–> tag becomes redundant.

    If nobody contradicts this (and I’m hoping somebody will), I’ll add a warning to the Codex.

    As it happens, I have found a workaround that I think I can live with. This mini-loop outputs an unordered list of a configurable number of posts, with a short excerpt.


    $posts = get_posts('numberposts=10');
    foreach ($posts as $post) :
    if ($title_was_printed == false) {$title_was_printed = true; print "<h2>Latest Blog Entries</h2>";}
    <li><small><?php the_time('F jS, Y') ?></small><br />
    <a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a><br /><?php the_excerpt(); ?>
    if ($title_was_printed == true) {
    <?php } ?>

    I never use a Page for front – always home.php with customized Loop(s) and/or plugins and never had this “more” problem.

    I know how to make a html splash page and use it as a static homepage, but most clients using WordPress as a CMS will want to be able to edit their homepage like any other WP Page.

    My testing shows that the <!more–> tag fails if the blog index is not displayed on the homepage. This happens on clean install of WP with no other modifications or plug-ins.

    Please, can you explain what is: “front _ always home.php”
    I cannot find any information about this by searching.

    Well, actually, you may be able to do something like this

    <?php query_posts('cat=-0'); //gets all posts
    $wp_query->is_home = true;
    load_template( TEMPLATEPATH . '/index.php'); //loads index

    I’m not responsible for any side effects 🙂

    home.php is a valid template file ina theme and will always take precedence over the index.php.

    What I did for a client who wanted different things on the “frontpage”:
    made a home.php
    in the template included the “get-a-post” plugin
    and even more then once!
    had a customized Loop… basically 4 different elements (blocks?) and all editable from the admin panel.
    Since I am code-illiterate I just use the built-in features and plugins written by clever guys 🙂

    Moshu was speaking of home.php. Basically, You take index.php and rename it home.php and add your custom stuff there for your static front page.
    I have set this up for clients many times without the “more” tag failing.
    I admit your code looks to be sound, but doing a home.php costs you little at this point, no?

    Sorry Moshu – you beat me to it with a better explanation.

    When I try alphaoide’s suggestion I get the full text of each post with no break at <!–more–>.

    That plug-in looks useful for lots of other things Moshu, thanks for the tip!

    samboll, I know how to make the home.php method work, but in this case the client does NOT want the Blog index on the homepage at all – he wants to see it when you click the link “Blog” or “News”. He also wants to to be able to edit the homepage via the normal Page admin interface.

    It still seems to me that it is NOT possible to have a WP-editable static homepage AND and normal Blog index as an internal page correctly using the more tag.

    Will the client have more categories or only “News”?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘<!–more–> fails when index loads from template’ is closed to new replies.