Show specific page on main index instead of latest

There are 3 latest pages displaying on my WP. Here’s the code.

<div id="main_posts">
<?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=3'.'&paged='.$paged . '&post_type=page' );
?>
<?php //query_posts('showposts=3'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="main_post">
    <?php $image = get_post_meta($post->ID, 'Image', true); ?>
        <a href="<?php the_permalink(); ?>">
            <img class="post_image" width="251" height="292" src="<?php echo $image; ?>" alt="" />

            <div class="main_post_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    </div>

I want to put 3 specific pages that I want on the main index page. How do I make it so?

Answer

This should work by putting the good IDs. The paged attribute is useless here as you’ll always show the same posts.

<div id="main_posts">
<?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query(array(
        'showposts' => 3,
        //'paged' => $paged,
        'post_type' => 'page',
        'post__in' => array(1, 2, 3) // Your post IDs
    ));
?>
<?php //query_posts('showposts=3'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="main_post">
    <?php $image = get_post_meta($post->ID, 'Image', true); ?>
        <a href="<?php the_permalink(); ?>">
            <img class="post_image" width="251" height="292" src="<?php echo $image; ?>" alt="" />

            <div class="main_post_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    </div>

Attribution
Source : Link , Question Author : TM23 , Answer Author : Mathias

Leave a Comment