Forums

[resolved] Show last post and last page on front screen (3 posts)

  1. LapD
    Member
    Posted 2 years ago #

    Hi!

    I am working on a site and got to a dead end. I have alot of pages, while i use posts only for news.

    Now i want to display 2 thing on my front page. First would be my latest post (news) and the second would be the latest page that was published (my articles).

    Can i do this with some kind of plugin or can some one help me with the code for this?

    Thanks!

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    <?php
    $types[0] = 'post';
    $types[1] = 'page';
    
    foreach ($types as $type) {
      $args=array(
        'orderby' => 'date',
        'order' => 'DESC',
        'post_type' => $type,
        '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() ) {
        echo 'Latest ' . $type ;
        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;
      } //if ($my_query)
    } // foreach
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. LapD
    Member
    Posted 2 years ago #

    Damn that worked like a charm :D

    Thank you very much!

Topic Closed

This topic has been closed to new replies.

About this Topic