Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • The Loop in Wordpress

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 271
    Comment on it

    The Loop

    The Loop is PHP code used by WordPress to display posts. Using The Loop in WordPress we can display each post in the current page.

    In wordpress have_posts() simply calls into $wp_query->have_posts() checks, if there are any posts exists or not.
    And the_posts() simply calls $wp_query->the_posts(), which advances the loop counter and sets up the global $post variable as well as all of the global post data. Once we have exhausted the loop, have_posts() will return false and we are done.

    Example:-

    <?php while ( have_posts() ) : the_post(); ?>    
        <h2>
            <a href="<?php the_permalink(); ?>">
                <?php the_title(); // title of the post. ?> 
            </a>
        </h2>
        <small>
            <?php the_time('F jS, Y'); // time of the post ?>
        </small>
    
        <div>
            <?php the_excerpt(); // display unique content. ?>
        </div>
        <div class="entry">
            <?php the_content(); // whole content of the post. ?>
        </div>
    <?php endwhile; ?>
    

    Simple Example:-

    Visit my next blog The Loop in WordPress -Part 2 to know about the_title(), the_time() the_content() the_excerpt() Loop in WordPress.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: