post-page

The “More” Tag on a WordPress Page

31
responses
by
 
on
July 9th, 2007
in
HOW-TO, WordPress FAQs, WordPress Tips

Nathan Rice wrote about WordPress’s ability to make any page a homepage. One problem I ran into using the technique of pages was the inability to use the <!--more--> tag to display partial posts. Apparently this is default behavior (for good reason) on pages. However, when using Nathan’s technique, I found myself in a unique situation where I only wanted to show a partial post (on a page) if the post was making use of the <!--more--> tag (apparently, I’m not alone).

The technique is rather simple. Simply declare a variable named $more as a global and set it to false right before showing your content. If you wish to resume normal behavior after the content is shown, simply set the variable back to true.

<?php global $more; $more = false; ?>
<?php the_content('Continue Reading'); ?>
<?php $more = true; ?>

heading
heading
31
Responses

 

Comments

  1. Marc says:

    Newb here – With WP’s ability to make any page a homepage, can one make more than one page (within a given WP blog) a ‘homepage’ and make use of multiple domain names (not subdomains) for each one of those ‘homepages?’

  2. adam (39 comments.) says:

    @marc-
    that relies on your hosting configuration, not wordpress. it depends from host to host.

  3. Nathan Rice (3 comments.) says:

    Ron,
    I actually had a client ask me for something similar … and I opted to use a page excerpt instead of using the more tag (although either option is fine). I used the page excerpt plugin here:
    http://blog.ftwr.co.uk/wordpress/page-excerpt/

    It adds an “optional excerpt” field to the page edit screen that you can put anything in. Just call the_excerpt like you would for a post, use query_posts and the loop to specify the page to call, and you’re done.

    Oh, and if you were looking for a site to link to for my name, you can just like to rockinthemes.com :-)

    Thanks for the hat tip, by the way :-)

  4. Jenny (24 comments.) says:

    wait, what? I’m lost.

  5. Ronald Huereca (39 comments.) says:

    Jenny,

    If you are using a page instead of index.php as your main page on a WordPress install, this technique allows you to use the “more” tag. I would follow Nathan’s example over at Blog Herald and go from there as needed.

  6. Jonathan (81 comments.) says:

    @Ronald
    Awesome hack. Will put this in the recipe book for future use.

    @Nathan
    Sheesh, I wish I’d known about that plugin a year ago! I’ve been manually adding my “excerpts” to pages (I use the excerpt as a sub-heading.)

  7. Vincent (1 comments.) says:

    Man. Wish I’d known this three or four months ago.

    I had a client who needed “articles” published on one page and “tips” published on another, with editable text before the individual posts, which they wanted shortened with more–so I created a page template, not knowing that the more tag wouldn’t work. Ended up just using categories.php along with category description before the posts instead of the page template and page content itself.

  8. Otto (215 comments.) says:

    I fail to see why that would work. I mean, what does the more link to, and what happens when you click on it? I would expect that it would link to the page’s permalink, but when you click on it, you’re going to get that same thing (since you’re using a page template) and the more link is just going to display again.

    How do you view the content after the more link in this situation?

    • Jasper (1 comments.) says:

      I agree. Tried the code on page.php and it did not work. As I understand now I would need a custom query to realize this. Not sure yet how, but looking into it. Some details on this in the article would be awesome.

  9. Dave J. (Scoop0901) (5 comments.) says:

    Thanks for passing along and sharing an excellent tip, Mark! I am in the middle of developing several sites, including a large organization site using WordPress as a CMS platform, and this was a challenge recently identified. The tip came made the solution simple.

    Cheers!
    Dave

  10. Ronald Huereca (39 comments.) says:

    Otto,

    If you use the technique without doing a “query_posts” first, then you’ll get the result you mentioned in your comment. I referenced Nathan’s article at the beginning of the post, so I’m assuming you’re trying to do something similar.

  11. Nathan Rice (3 comments.) says:

    Otto,
    Looks like Ronald beat me to it, but I’ll elaborate a bit more. This tip is talking about homepage design … not page.php design. You’re right, using the more tag on a single page would be silly. But on the homepage, it can be used to handle things like an “about me” box in the sidebar that gives an excerpt of your about page, then links to the rest. The possibilities are endless when it comes to using WP as a functional CMS.

    Nathan

    • dydi nadya says:

      hi nathan,

      i understand what u trying to said.
      but can u pleassssssssssssssseeeeeeeeeeeee gimme the more details explaination.like where should i put the code i stated in ur article, in which php files, what lines and everything in very very details..
      cuz my read more link did appear but doesnt function..huk..helpp =(

  12. dizzah says:

    i am a newbie to the wordpress, and i face the same problem you mentioned then i found your article here so thanks for the tips first, but, i still dont know how to solve that problem in your way,i don’t know where i can put your code in, is it in the page.php or in the template page that i created for my own homepage?
    or can you email me the detailed solution? thanks so much

  13. Ronald Huereca (39 comments.) says:

    dizzah,

    Check out Nathan Rice’s article. You can also check out my article on the loop.

    The WordPress codex will be your new best friend. The WordPress codex is a good resource for information on WordPress pages.

    What you will have to do is create a new page template, and put the code I mentioned within the loop. You will then have to create a new page within WordPress and use the page template you created as a template. From there, you will have to tell WordPress to use your page as the default home page (Options -> Reading) and go from there.

    I hope that helped.

  14. Leo (1 comments.) says:

    Thank you, this was really useful. I couldn’t get the more tag to work anywhere within the theme I’m using, but this solved that problem.

  15. Thomas Gigold (1 comments.) says:

    Thank You! This saved my day :-)

  16. dydi nadya says:

    hey all..

    please help me. im doing a weblog for my uni project.
    the proble is, after i follow what’s nathan said, the read more now appear in my front page.however, when click the link, it doesnt function at all..pls help me.. im really a newbie in this…

  17. Courtney says:

    Hi, thanks for this — this is what I was looking for. I copied and pasted your code into the loop, however, and nothing changed. Is there something else that needs to be done?

    Thanks.

  18. Reino says:

    Great! This works for me! Great and simple solution to use the more tag on wordpress pages.

  19. Greg (1 comments.) says:

    This saved me a lot of hair pulling, thank you!

  20. Mike (1 comments.) says:

    My post pages are about 1000 words. A very long page. I would like to split them up into 2 or 3 pages. How can I do that?
    So… http://www.example.com/longpost/ would display on 2 or 3 pages, instead of 1, with a More tag.
    Is this possible?

  21. Jon Nixon (1 comments.) says:

    you rock. I’ve been searching for this for hours. Thanks. – Nixon

  22. matthew says:

    Thank you ! Great and simple solution to use the more tag on wordpress pages.

  23. chris medborger says:

    This was some of the best code I have ever come across. I couldn’t figure out how to use the tag in my custom page templates.
    Saved me a lot of work!
    Thank you Ronald!

  24. Casey Keppel-oOmpton (1 comments.) says:

    I really appreciate you posting this – I had tried lots of other hacks and just couldn’t get it to work – thank you a ton


Tweetbacks

  1. svertrees (Susan Vertrees) (1 comments.) says:

    Figured out why I couldn’t get just partial postings to show on static homepage of WordPress site. http://tinyurl.com/6ohdwr


Trackbacks/Pingbacks

  1. […] This plugin enables bloggers who wish to use a ‘page’ as the homepage of a WordPress blog. For more information on pages, visit the BlogHerald’s article on making any page the homepage. Also visit my article on using the “more” tag on a WordPress page. […]

  2. […] tag to clip posts on any pages other than the specified homepage. So, I did a little searching and found a really simple fix for this problem over at Weblog Tools Collection. […]

  3. […] tag wasn’t working.  After a quick Google search I came across this page http://weblogtoolscollection.c.....ress-page/ that provided a solution.  The “solution” didn’t work and after I searched the […]

  4. […] There’s a small problem with having what essentially amounts to two blog homepages…one for the tutorials section and another for the blog section. The problem is that I have to tell WordPress to use one as the actual blog homepage, which, in my case, I’ve already set up to be the tutorials page. By default, WordPress won’t let you use the “more” tag to clip posts on any pages other than the specified homepage. So, I did a little searching and found a really simple fix for this problem over at Weblog Tools Collection. […]

Obviously Powered by WordPress. © 2003-2013

page counter
css.php