WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WordPress the_title displays page title (3 posts)

  1. ronnyrook
    Member
    Posted 1 year ago #

    Hello WordPress Users,

    I'm currently using the following code to display posts:

    $args_blog = array( 'numberofposts' => 10, 'category' => 2, 'orderby' => 'post_  date' );
    $list_of_blog = get_posts( $args_blog );
    
    foreach($list_of_blog as $blog) :
        setup_postdata( $blog ); 
    
        if( has_post_thumbnail( $blog->ID ) ) :
            $image_blog = wp_get_attachment_image_src( get_post_thumbnail_id( $blog->ID ), 'single-post-tumbnail');
    
             if( $image_blog ) :
                 echo '<img src="'.$image_blog[0].'" class="img" width="290" height="290" />';
              endif;
    
        endif; 
    
        the_title();
        the_excerpt();
    endforeach;

    The content and the image of the post are working.
    But the_title is showing the title of the page?

    What can I do about this or is this just a bug or something?

  2. Justin
    Member
    Posted 1 year ago #

    I would not use that snippet. Things will not work very well that way. Look into using http://codex.wordpress.org/The_Loop

  3. ronnyrook
    Member
    Posted 1 year ago #

    Thanks, I fixed this using the loop you suggested :)!

Topic Closed

This topic has been closed to new replies.

About this Topic