Forums

[resolved] problem with home.php and page content (4 posts)

  1. jjmac
    Member
    Posted 2 years ago #

    I have a custom design I am trying to get working. In my home.php file I have <?php echo $pageContent; ?> this doesn't get the content when I have the page template set to "Home" but when I set the page template to "Default Template" my content shows up. Here's some code from home.php `<?php
    /*
    Template Name: Home
    */
    ?>
    <?php
    include_once('custom.php');
    query_posts('page_id=' . $homePageId);
    if (have_posts()) : while (have_posts()) : the_post();
    fetchCustomValues();
    $pageHeading = $post->post_title;
    $pageContent = $post->post_content;
    endwhile; endif; ?>

    <?php include_once('header.php'); ?>

    <div class="rightcol_home">
    <h2>Security. Trust. Reliability</h2>

    <?php echo $pageContent; ?>
    </div>`

    Any ideas? Thanks!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Try using <?php the_content();?>

  3. s_ha_dum (was apljdi)
    Member
    Posted 2 years ago #

    $post->post_content should echo the content just fine, but you lose a lot of functionality that way-- formatting, mostly. the_content() is better, but only works inside the loop. Your problem, I think, is this: you set $pageContent at each iteration of the loop, and at the next iteration it is overwritten. I'm betting that by the time you leave the loop its been overwritten by an empty string. Try $pageContent[] = $post->post_content; and then use <?php print_r($pageContent); ?> after the loop and see if you get something different.

  4. jjmac
    Member
    Posted 2 years ago #

    Thanks for the advice. It still wasn't working so I ended up using a trimmed down version of blog.php for my home.php and index.php files. It's working so I can finally stop thinking about it! Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic