#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    335
    Rep Power
    247

    Can't get Wordpress to show content?


    Hi,

    I seem to be getting no-where fast with Wordpress.

    I have ...
    Code:
    		$myposts = get_posts("numberposts=2&category_name=home"); 
    		foreach($myposts as $post) : 
    			the_title();
    			the_content(); 		
    		endforeach;
    But all that shows is the titile and no content?

    I've tried
    Code:
    		$myposts = get_posts("numberposts=2&category_name=home"); 
    		foreach($myposts as $post) : 
    			the_post();
    			the_title();
    			the_content(); 		
    		endforeach;
    But then nothing shows whatsoever?

    I cannot get the content of the post to show, nor the featured image, all I seem to be able to output is the_title()?

    Any ideas

    1DMF
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    335
    Rep Power
    247
    OK, it turns out i need to prepare the returned result
    Code:
    setup_postdata($post);
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    335
    Rep Power
    247
    OK, still the featured image doesn't show?

    How do I get wordpress to show the whole damn post , correctly formated as a section?
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    119
    Rep Power
    33
    Not sure why you have set up your own loop instead of using Wordpress' but this is what I use which shows the title, content and featured image:

    PHP Code:
    <?php while ( have_posts() ) : the_post(); ?>
                <section>
                    <div class="loop-post">
                        <?php if (has_post_thumbnail()) : ?>
                            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium'''); ?></a>
                        <?php endif; ?>
                        <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                        <?php the_content(); ?>
                    </div>
                </section>    
            <?php endwhile; ?>
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    335
    Rep Power
    247
    Thanks for the code.

    How is that going to select specific posts in a particular category and display them in a page?

    I must be missing something here

    Thanks,
    1DMF
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    119
    Rep Power
    33
    Sorry, I didn't look properly at what you were doing so have just provided the code to resolve your issue with content and images not appearing.

    Using get_posts will only display certain information - read here:
    Access all post data
    Some post-related data is not available to get_posts by default, such as post content through the_content(), or the numeric ID. This is resolved by calling an internal function setup_postdata(), with the $post array as its argument:

    <?php
    $args = array( 'numberposts' => 3 );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
    <?php endforeach; ?>
    Hope this helps
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    335
    Rep Power
    247
    Thanks.

    I was close, just needed a little nudge.

    Much obliged.
    1DMF
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!

IMN logo majestic logo threadwatch logo seochat tools logo