WordPress.org

Ready to get started?Download WordPress

Forums

Where can I find the Loop? (3 posts)

  1. darrenlc
    Member
    Posted 7 years ago #

    I have completed a new install of WordPress and have chosen not to allow WordPress to create my home page. I want to embed the loop into an existing webpage.

    First major problem: Eh... where is the loop?

    I thought it was supposed to be in the index.php file created by WordPress. It's not. I thought it might be in the homepage-index.php file created by WordPress. It's not. I looked through many other *.php pages and still did not locate the loop.

    Interestingly enough, when I navigate my browser to the directory that WordPress resides in, the WordPress default page comes up all pretty and proper. When I click View -> Source on this page I can see all of the pertinent code, including the much sought after loop.

    Yet I still can't find the file it is in. I'm at a loss and feeling very inferior at this point. I'm having this recurring dream that my name is Mr. Anderson and there's a voice emanating from a bug in a line of code depicting a Campbell's Soup can: "The Loop has you, Mr. Anderson". Can/will someone help me locate this elusive "loop"? I want to find out how deep the nested while loop really goes...

    Thanks for reading my cry for help. ^_^

  2. BPartch
    Member
    Posted 7 years ago #

    Hello

    The "loop" is at your-ste.com/wp-content/themes/theme-name in the file(s) index.php, archive.php, single.php, page.php and search.php

    http://codex.wordpress.org/The_Loop

  3. 3stripe
    Member
    Posted 7 years ago #

    The loop is all around you. Feel the loop.

    Ok sorry, erm seriously, the loop might look something like this in it's basic form:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="post">
    <h2><?php the_title() ?></h2>
    <?php the_date() ?>
    <?php the_content() ?>
    </div>
    <?php endwhile; else: ?>
    Sorry, no posts could be found to match your criteria.
    <?php endif; ?>

    The line to look for is "<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>" which always marks the start of the loop.

    What theme are you using? The default theme should have the loop in the index file...

    For a more eloquent description of the loop, try http://mattread.com/archives/2005/04/wordpress-is-not-php/

Topic Closed

This topic has been closed to new replies.

About this Topic