WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I got this code to show my thumbnails images and videos on my blog page, but when i try to use to show the thumbs in another page, it doesnt works.

Function to display images and videos thumbs

function show_blog_posts() {
global $post, $blog, $posts;
$first_vid = '';
$output = preg_match_all('/<iframe.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_vid = $matches [1] [0];

if ($output == '1') {
    echo '<iframe width="100%" height="400" src="';
    echo $first_vid;
    echo '" frameborder="0" allowfullscreen></iframe>';
} else { ?>
            <?php the_post_thumbnail('large');?>

My shortcode

add_shortcode('recent_blog_posts', 'shortcode_recent_blog_posts');

function shortcode_recent_blog_posts($atts) {

        $str = '';
        $args = array( 'numberposts' => 3, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
        $postslist = get_posts( $args );

        foreach ($postslist as $post) : setup_postdata($post); 
            $str .= '<div id ="article-section-box2" class="span3">';
                            $str .= '<div id= "image1" class="image-arcticle">';     
                            $str .= show_blog_posts($post->ID, '');
                            $str .= '</div>'; 
                            $str .='<p class="article_text">'.excerpt(18).'</p>';
                            $str .='</div>';

        return $str;

Is there anything wrong? Thanks

share|improve this question
Turn on debugging so you can learn more than "it doesnt work". – Wyck Jan 28 '13 at 15:46
debugging information – s_ha_dum Jan 28 '13 at 15:48
Debugging is informing : Notice: Trying to get property of non-object in C:\xampp-portable\htdocs\wordpress\wp-content\themes\Pabloswebsite\functions.php on line 28 and 29 – Chead Jan 28 '13 at 16:20
up vote 0 down vote accepted

You are passing show_blog_posts two parameters...

$str .= show_blog_posts($post->ID, '');

... but you have defined it to accept none...

function show_blog_posts() {

There seems to be some disconnect between your two blocks of code. I'd suggest actually passing the $post object the way that you are trying to.

function show_blog_posts($post = NULL) {
    global $blog, $posts;
    if (empty($post)) {
        global $post;
    // the rest of your function

No idea what that second parameter is supposed to be.

share|improve this answer
I did what u said but keeps "not working" to me yet :( sry for my english – Chead Jan 28 '13 at 16:13
What changed between when you posted that comment and when you accepted the answer? – s_ha_dum Jan 30 '13 at 23:38
You were right, my code is working now. thanks! – Chead Feb 1 '13 at 4:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.