WordPress.org

Ready to get started?Download WordPress

Forums

How to add post content to a page (4 posts)

  1. richardescobedo
    Member
    Posted 5 years ago #

    I'm having a bit of a hard time displaying the post content on a page. I don't know what else to add -- when I use the following code my post content doesn't display.

    <?php get_header(); ?>
    
    	<div id="PageContent">
    	<div class="general_column_text" id="Column1">
    			<div class="sectionHeader"><img src="images/home/from_the_trail.jpg" alt="From The Campaign Trail" /></div>
    
    			<div class="title"><a href="<?php the_permalink() ?>" title="<?php _e('Permanent Link to', 'default'); ?> <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
    			<div class="description">
    			<?php $content = get_the_content(); ?>
    			</div>
    
    		</div>
    
    	<?php get_sidebar(); ?>
    
    	<?php get_footer(); ?>

    But, when I use this code, my text is indented, throwing off all of my text and ruining my layout.

    <?php
     $lastposts = get_posts('numberposts=3');
     foreach($lastposts as $post) :
        setup_postdata($post);
     ?>
     <h2><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h2>
     <?php the_content(); ?>
     <?php endforeach; ?>

    Does anyone know what to do? Any help would be much appreciated!! :-)

    Richard

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Any reason why you can't just use The Loop?

  3. stvwlf
    Member
    Posted 5 years ago #

    hi

    in your first code it needs to say either

    <?php $content = get_the_content();
          echo $content;
     ?>

    or else
    <?php echo get_the_content(); ?>

    The second code's problem sounds more like issues. You have an <h2>in the 2nd which is not in the 1st. You can either create CSS for <h2>or change <h2> to <div> as in the 1st code.

  4. richardescobedo
    Member
    Posted 5 years ago #

    esmi:

    Thanks for the tip -- I went and implemented The Loop and things are working great!

    http://www.freshmanforrichard.com

Topic Closed

This topic has been closed to new replies.

About this Topic