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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 341
    Comment on it

    In My previous blog I have explained have_posts and the_post Loop but there are some more WordPress loops which I am explaining in this blog below.

    The Loop :- As I already explained in my previous blog, 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.

    Now lets get started with the loops used in WordPress-

    the_title(); the_content(), the_time(), the_excerpt()

    the_title();:- It Displays or returns the title of the current post. This tag may only be used within The Loop, to get the_title() of a post outside of the loop use- get_the_title(); .

    the_content(); :- It Display the full content of the current post. this tag may only be used within The loop, to get the content of a post outside of the loop use- get_the_content(); .

    the_excerpt(); :- It Display the unique content of the current post and generate <---read more---> option to display the full content of the current post. In the_excerpt() , we can display limited content or limited words. this tag may also be used within The Loop, to get the_excerpt() outside the loop use- get_the_excerpt(); .

    the_time(); :- It Displays the time of the current post. To return the time of a post, use- get_the_time().

    Example :-

    <?php while ( have_posts() ) : the_post(); ?>    
        <h2>
            <a href="">
                <?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(); // content of the post. ?>
        </div>
    <?php endwhile; else: ?>
    <p><?php echo "Sorry, no posts matched your criteria."; ?></p>
    

 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: