SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2010
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding 'page' content to a custom page template

    Hi,

    I've created a custom template ('newshome') to display news posts on a page of a site 'myurl/news'. The 'newshome' template is just category.php with:
    Code:
    <?php query_posts("posts_per_page=5") ?>
    at the start to display recent news stories. Before the page displays these news blog posts though, I'd like to be able to have a static introductory paragraph at the top of the page which would be edited from the dashboard for the news page. I thought that just placing
    Code:
    <?php the_content(); ?>
    in the appropriate place would do the trick, but it doesn't. I figured this from looking at page.php and this is the only php code that seems to drag in the user created content.

    In the theme I'm using this is immediately followed by:
    Code:
    <?php get_template_part( 'loop', 'category' ); ?>
    so, from reading around in the codex a bit, I figure that this is part of my issue? i.e the call to the_content function needs to be inside the loop but the loop is contained in another file (loop.php)?

    If that's correct, how might I crowbar the_content into place? Any thoughts greatly appreciated!

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If your wanting to use the content you set in the page itself then using the_content() after the query_posts() function won't work as it has declared a new loop which overwrites the old one, to overcome this simply put the_content() before the query_posts() function which will allow it to return the page content while the original loop is still active.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •