Asif Mehmood
Asif Mehmood

Reputation: 473

Displaying specific post title on the front page in wordpress

I want to display the specific post title/content in the front static page.Remember not all posts just specific. So can anybody guide me how to do that..

Upvotes: 0

Views: 144

Answers (2)

Asif Mehmood
Asif Mehmood

Reputation: 473

<?php 
  $titles=array();
  $contents=array();
  $links=array();
  // the query
  $the_query = new WP_Query( array(
    'posts_per_page' => 3,
    )); 
  ?>
 <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

  <?php $titles[]=get_the_title(); ?>
  <?php $contents[]=get_the_content(); ?>
  <?php $links[]=get_the_permalink();?>

  <?php endwhile; ?>

and now printed the value in my page wherever i wanted

<?php echo $titles[0]; ?>
<?php echo $titles[1]; ?>
<?php echo $titles[2]; ?>

And same for other declared arrays. :)

Upvotes: 0

Ahmed Ginani
Ahmed Ginani

Reputation: 6650

Yes you can get specific posts in front page by passing post ids with array in include parameter something like this,

<ul>
<?php

global $post;
$args = array(
 'offset'=> 1,
 'include' => array(1,2,3)  // PASS POST ID IN ARRAY
 'post_type' => 'post', );

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php the_content(); ?>
    </li>
<?php endforeach; 
wp_reset_postdata();?>

</ul>

Hope this works.

Upvotes: 1

Related Questions