Forums

[resolved] Content Won't Display On Static Page? (5 posts)

  1. leafmealone
    Member
    Posted 1 year ago #

    This all should be pretty simple, which is why I'm kicking myself here. I am simply trying to make a Contact page for my site. I've made a contact.php file which has basically the same layout as the main index.php file, and consists of:

    <?php
    /*
    Template Name: Contact Page
    */
    ?>
    
    <?php get_header(); ?>
    
    <?php include('leftsidebar.php'); ?>
    
    	<div id="main-content" class="contact">
    
    		<div class="maintitle"><?php the_title(); ?></div>
    
                    <?php the_content(); ?>
    
    	</div>
    
    <?php include('rightsidebar.php'); ?>
    
    <?php get_footer(); ?>

    And then I write a page, give the Contact Page Template, and publish it. When I go to my Contact page, everything looks fine, and it even inserts the Title of the Page I wrote, but the content is conspicuously absent. Just...nothingness.

    I'm sure I'm an idiot, but why?

  2. Anonymous
    Unregistered
    Posted 1 year ago #

    If I'm understanding you correctly, you want to create a contact us page with the same template on your website. Take a look at my site and let me know if this is the idea you are going for. Compare the index page with our contact us page.

    http://www.enviropro.biz

  3. leafmealone
    Member
    Posted 1 year ago #

    LSJ, that's exactly right. Even down to the content of the contact form you have below, that's just what I'm trying to accomplish. I know this is a very basic question, thanks for helping out.

  4. Otto42
    Moderator
    Posted 1 year ago #

    Your page does not have The Loop. You never pull the post content, so "the_title" and "the_content" are undefined.

    You MUST have a Loop. Even though the page only has one entry, it still must Loop.

    Like this:

    <div id="main-content" class="contact">
    		<?php while (have_posts()): the_post(); ?>
    		<div class="maintitle"><?php the_title(); ?></div>
                    <?php the_content(); ?>
    		<?php endwhile; ?>
    	</div>

    That while stuff is not optional.

  5. leafmealone
    Member
    Posted 1 year ago #

    Otto,

    Thanks a million. That worked - I thought that the Loop was only necessary if you were cycling through many posts/pages. Thought if there was only one, the_content would default to that. Foolish of me.

    Marked as resolved, I appreciate it.

Topic Closed

This topic has been closed to new replies.

About this Topic