WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How Display Content on a Custom Page (9 posts)

  1. Patrick Orr
    Member
    Posted 4 years ago #

    I am using wordpress as a CMS. I have created a custom page template to have a page specific side bar. The only problem I am encountering is that I cannot find how to display the content from the actual 'wordpress page publishing tool'.

    Here is what the custom page code looks like:

    <?php
    /*
    Template Name: Day Tips
    */
    ?>
    
    <?php get_header(); ?>
    <?php include (TEMPLATEPATH . '/sbdaytrips.php'); ?>
    <?php the_content(); ?>
    <?php get_footer(); ?>

    I assumed that <?php the_content(); ?> would fetch the content that I create in the wordpress dashboard, but it does anything.

    Any ideas?
    Thanks

  2. Deckster0
    Member
    Posted 4 years ago #

    You forgot to create "theloop" for the page template.

    If I remember correctly, the_content() only works inside the loop.

  3. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    the_content would work.....with the rest of the loop

    http://codex.wordpress.org/The_Loop
    http://codex.wordpress.org/The_Loop_in_Action

    you gotta tell WP to load posts at very least...... some kind of query

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    etc.....

  4. Patrick Orr
    Member
    Posted 4 years ago #

    hmm thanks for the heads up.
    Is there a way to start a look without looking for posts?
    There are not any posts on this website... and without posts it just continues to look for them.

  5. Patrick Orr
    Member
    Posted 4 years ago #

    I tried running and if loop with no success:( The if loop executes, but it doesn't load the content still...

    <?php get_header();?>
    <?php include (TEMPLATEPATH . '/sbdaytrips.php');?>
      <?php if(have_posts()) :?>
        <div class="post">
            <div class="entry">
                    <?php the_content(); ?>
            </div>
        </div>
    <?php endif; ?>
    <?php get_footer(); ?>

    It seems kinda sloppy to have to run an if loop just to do this, does anyone else have a better idea?

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    the best bet would be to model the template after page.php

    you still have an incomplete loop.....

    <?php if(have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    but if you are just trying to have a special page specific sidebar show up on a certain page, I believe you could just edit your page.php with a conditional statement to load the special sidebar for a specific page.

    http://codex.wordpress.org/Conditional_Tags

  7. syncbox
    Member
    Posted 4 years ago #

    <?php get_header(); ?>
    <?php include (TEMPLATEPATH . '/sbdaytrips.php'); ?>

    <?php //loop to get content
    if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    <?php the_content(); ?>

    <?php endwhile(); ?>

    <?php get_footer(); ?>

    That said, you can create a custom field with text content to display IF it exists in or outside of the loop.

    For example, using c2c's excellent get custom plugin, you can add a custom field to the desired page (let's call the key "default-text") and call that from your custom page template outside of the loop with the plugin's c2c_get_recent_custom('default-text'); function. But of course, that means the text will display for every page that uses your custom template, which is great if you have a common element for all pages.

    Within the loop however, you can call SPECIFIC text (default-text) for the current page only IF the custom field 'default-text' exists for that page using c2c_get_custom('default-text');

    It will only display the specific text WHEN and IF that field exists for THAT page.

    You can read about the plugin here:

    http://coffee2code.com/wp-plugins/get-custom-field-values/

    It's the one of my MUST-USE plugins for every site done as a CMS

  8. Patrick Orr
    Member
    Posted 4 years ago #

    Thanks alot!

  9. adjustreality
    Member
    Posted 3 years ago #

    @syncbox

    few corrections to your code, there is also a simpler way to write it:

    <?php get_header(); ?>
    <?php include (TEMPLATEPATH . '/sbdaytrips.php'); ?>
    //begin loop
    <?php if (have_posts()) : while (have_posts()) : the_post();?>
    <?php the_content(); ?>
    <?php endwhile; endif; ?>
    <?php get_footer(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic