Support » Themes and Templates » Specific Post in a Page

  • Resolved samwebcornwall

    (@samwebcornwall)


    Hi

    This is my first post on here, I’ve searched through the codex and I’m looking to do something fairly straightforward (I hope!) I would like to call a specific post into certain templates.

    I have my templates set up and am calling posts through the posts parent category via a custom field, ok, but this seems a little overly complicated. Is there a snippet of PHP that I can put between my <div> </div> in my php template to call a unique post by id alone?

    Sorry if this is in the codex but I really can’t seem to find it! Thank you so much if anyone can help

    If you look at my site I just have a holding page – the URL I’m working on is actually http://webdesignercornwall.com/?page_id=13

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    //display post id 47
    $args=array(
      'post__in' => array(47),
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_content();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Hi Michael H

    Thankyou so much! You’ve made my day… no year!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Specific Post in a Page’ is closed to new replies.