How can I use get_template_part() for specific post using get_post() in wordpress?

admin

Administrator
Staff member
I am creating my first wordpress theme.
I'm currently using loops and get_template_part() for displaying my post list like this:

Code:
while ( have_posts() ) {
    the_post();
    get_template_part( 'content', get_post_format() );
}

this works great and is loading the content.php as template for post.

I want to display a specific post using get_template_part() at the end of the regular posts output.
I added this for displaying my post with Id 123 after my while loop:

Code:
get_post(123);
get_template_part( 'content', get_post_format() );

So the total code is:

Code:
while ( have_posts() ) {
    the_post();
    if($post->ID != 123) // exclude Post 123 from output
        get_template_part( 'content', get_post_format() );
}

get_post(123);
get_template_part( 'content', get_post_format() );

But this just repeats the last Entry from the regular loop.
Can anyone help?

Thanks and regards
Jan