• IS there a way I can check if a post in a query posts list is the current post.

    I have tried: `<?php if(is_single( ‘the_ID();’ )) { ?>
    `

    But it doesn’t seem to work.

Viewing 3 replies - 1 through 3 (of 3 total)
  • you could try to save the current post id into a variable (at the start of the template, before your query; i.e. $current_id = $post->ID;); then compare it in the query list.

    imho, is_single() would not work in a list of multiple posts;
    besides, the_ID() would output an post id, but would not be available as a string, you need get_the_ID() for that.

    Thread Starter narkiej

    (@narkiej)

    Thanks for that. You are correct

    is_single() is not working within query posts. How can I get it to function?

    example: (written without any syntax where not neccessary)

    get_header;
    
    <?php $current_post = $post->ID; ?>
    
    query_posts();if(have_posts()):while(have_posts()):the_post() THE LOOP
    
    <?php if( $post->ID == $current_post ) { echo 'this post from the list is the current post'; } ?>
    
    endwhile;endif END OF LOOP
    get_footer

    to get the current post id at the stasrt of your template, use this line:
    <?php $current_post = $post->ID; ?>

    to check the posts in the query posts list, use this line:
    <?php if( $post->ID == $current_post ) { echo 'this post from the list is the current post'; } ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘is_single the_ID’ is closed to new replies.