The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Can't get Wordpress to show content?
Discuss Can't get Wordpress to show content? in the PHP Development forum on Dev Shed. Can't get Wordpress to show content? PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 6th, 2012, 10:10 AM
|
 |
Contributing User
|
|
|
|
|
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
|

November 6th, 2012, 10:19 AM
|
 |
Contributing User
|
|
|
|
OK, it turns out i need to prepare the returned result
Code:
setup_postdata($post);

|

November 6th, 2012, 10:24 AM
|
 |
Contributing User
|
|
|
|
|
OK, still the featured image doesn't show?
How do I get wordpress to show the whole damn post , correctly formated as a section?
|

November 7th, 2012, 02:00 AM
|
|
|
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; ?>
|

November 7th, 2012, 05:17 AM
|
 |
Contributing User
|
|
|
|
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
|

November 7th, 2012, 05:40 AM
|
|
|
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:
Quote: 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
|

November 7th, 2012, 06:37 AM
|
 |
Contributing User
|
|
|
|
|
Thanks.
I was close, just needed a little nudge.
Much obliged.
1DMF
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|