WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to retrieve the content of a page only (5 posts)

  1. theoscrib
    Member
    Posted 5 years ago #

    Hi guys, for my blog I created my own template and I want to stuff it up with goodies like scriptaculous or dojo (haven't choosen yet). I want to show the content of a page only. So no html, no head, no body and no side bar etc. just the content. How can I get the content of a page. I don't know anything about PHP.

  2. Austin Matzko
    Member
    Posted 5 years ago #

    If you really want just the content of a page (in the WordPress sense of "page"), then create a page.php template file in your theme's directory with the following content:

    <?php
    the_content();

    Yep, that's it.

  3. theoscrib
    Member
    Posted 5 years ago #

    I have read that tutorial. But the problem is that in wp 2.7 I don't see how I can assign a template to a particular page.

  4. Austin Matzko
    Member
    Posted 5 years ago #

    If you want to assign this template to a particular page, then you need to amend it as so:

    <?php
    /*
    Template Name: Pure Content
    */
    the_content();

    and choose "Pure Content" under Attributes > Template when editing a page.

  5. theoscrib
    Member
    Posted 5 years ago #

    Yes it worked. Thank you so much for your help. I copied the page.php. Gave it a new name and removed the html wrapper. It looks like:

    <?php
    /*
    Template Name: Page only no html
    */
     ?>
    
     <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    		<h1 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h1>
    
    		<?php the_content("__('[...]')
    "); ?>
    
    	<?php endwhile; endif; ?>

    If you add a template wordpress sees that you have multiple templates and you can pick one from a drop down list. Isn't wordpress just amazing?

Topic Closed

This topic has been closed to new replies.

About this Topic