• Agent D

    (@agent-d)


    Hi,

    I want to insert one specific post in the homepage which is static. The below is the code I have for “index.php”

    <?php include(‘header_site_index.php’); ?>
    <?php include(‘home_mainscreen.php’); ?>
    <?php include(‘footer_home.php’); ?>

    I often update the content “home_mainscreen.php” and sometimes I would like to show one specific post from my site. Is it possible to do so? Please let me know. Thanks millions in advance!

    AD

Viewing 3 replies - 1 through 3 (of 3 total)
  • MichaelH

    (@michaelh)

    <?php
    $yourpostid = 201; // <--- replace with your specific post id
    $args=array(
      'p' => $yourpostid,
      '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>" 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().
    ?>

    Related:
    query_posts()
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

    Thread Starter Agent D

    (@agent-d)

    Hi, thank you for your answer. It works except that the title of the post doesn’t appear. I suspect that I need to do something with the line:

    <p>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></p>

    If you have any suggestion I really appreciate it. Thanks!

    <p><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>

    looks like maybe it should be

    <p><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show one specific post in the static front page’ is closed to new replies.