WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] <!--more--> fails when index loads from template (19 posts)

  1. JohnP
    Member
    Posted 8 years ago #

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


    <?php
    /*
    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?

  2. moshu
    Member
    Posted 8 years ago #

    What is "blog.php"? That's not a filename that WP would recognize as valid template file.

  3. JohnP
    Member
    Posted 8 years ago #

    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:

  4. JohnP
    Member
    Posted 8 years ago #

    Sorry, the second sentence in my question should read:

    But when I load the example.com/blog/ page...

  5. MikeUK
    Member
    Posted 8 years ago #

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

  6. JohnP
    Member
    Posted 8 years ago #

    The tag shows up in the code of example.com/blog/ as:

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

  7. MikeUK
    Member
    Posted 8 years ago #

    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!

  8. Joshua Sigar
    Member
    Posted 8 years ago #

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

  9. JohnP
    Member
    Posted 8 years ago #

    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.


    <?php

    $posts = get_posts('numberposts=10');
    foreach ($posts as $post) :
    if ($title_was_printed == false) {$title_was_printed = true; print "<h2>Latest Blog Entries</h2>";}
    ?>
    <ul>
    <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(); ?>
    </li></ul>
    <?php
    endforeach;
    if ($title_was_printed == true) {
    ?>
    <?php } ?>

  10. moshu
    Member
    Posted 8 years ago #

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

  11. JohnP
    Member
    Posted 8 years ago #

    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.

  12. Joshua Sigar
    Member
    Posted 8 years ago #

    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 :)

  13. moshu
    Member
    Posted 8 years ago #

    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
    http://guff.szub.net/2005/01/27/get-a-post/
    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 :)

  14. Samuel B
    moderator
    Posted 8 years ago #

    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?

    Edit**
    Sorry Moshu - you beat me to it with a better explanation.

  15. JohnP
    Member
    Posted 8 years ago #

    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.

  16. moshu
    Member
    Posted 8 years ago #

    Will the client have more categories or only "News"?

  17. MikeUK
    Member
    Posted 8 years ago #

    A development I'm working on requires several pages, each requiring a different editorial comment in the sidebar. It's at http://www.smokespeak.com.

    The first, index.php, page lets the <!--more--> tag work. None of the pages linked to by top menu items allow the <!--more--> tag to work. Same code though, contained in sidebar.php!

    Here's the code...

    <?php rewind_posts(); ?>
    <?php query_posts('showposts=1&cat=6'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div id="editor">
    <h1>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h1>
    <?php the_content(' <more>'); ?>
    </div>
    <?php endwhile; ?>
    <?php else : ?>
    <div class="editor">
    <?php _e("No blog entries could be located. If this error continues then please let me know!"); ?>
    </div>
    <?php endif; ?>

    Further ideas? Also, what file(s)/functions deal with this tag? Where is function code which defines a home/index page to work one way and a single Page to work another?

    Thanks guys!

  18. JohnP
    Member
    Posted 8 years ago #

    My problem has been solved even better!

    I finally installed and activated the Filosofo Home-Page Control pluggin, told it I wanted the "News" page to be the blog index, and Bob's yer uncle!

    My WP-created Page is now at http://www.example.com/ and the standard blog index is at http://www.example.com/news/, just as I wanted. The more tag is functioning perfectly.

    The pluggin is overriding my news_php template with the mini-loop described above.

    I had tried the plugin previously, but that was before I discovered my server wasn't writing to .htaccess.

  19. Just Thomas Misund
    Member
    Posted 8 years ago #

    I know this is a resolved topic, but I'm just curious:

    If I
    1) install WordPress in http://example.com/wp/
    2) create a WordPress Page http://example.com/wp/first-page/
    3) create a file http://example.com/index.php that says

    <?php
    header('Location: http://www.example.com/wp/first-page/');
    ?>

    Won't that solve the problem at hand? Nice and easy?

Topic Closed

This topic has been closed to new replies.

About this Topic