WordPress.org

Ready to get started?Download WordPress

Forums

update a in index page without reloading (1 post)

  1. pedenski
    Member
    Posted 2 years ago #

    can someone direct me on how to do this, im using wordpress; Im using get_posts to retrieve the newest post and display the 2 previous post in a <li> tag on my index page

    like below:

    This a new post!
     -old post 1
     -old post 2

    the desire i want is very simple, when a new post is being created, user's dont have to reload the browser to update the index page.

    Here's my get_posts as above.

    //DISPLAYS THE NEWEST POST
    <?php
    global $post;
    $args = array( 'numberposts' => 1, 'category' => 1 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<div class="post"><h1><?php the_content(); ?></h1></div>
    
    <?php endforeach; ?>	
    
    //SHOWS 2 PREVIOUS POST
    <?php
    global $post;
    $args = array( 'numberposts' => 2, 'offset'=> 1, 'category' => 1 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<li><?php echo get_excerpt(40); ?> - <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags