WordPress.org

Ready to get started?Download WordPress

Forums

Has my Loop gone "loopy"? (5 posts)

  1. davincim
    Member
    Posted 9 years ago #

    I was in the process of installing a plug that required modifying The Loop. I went to the codex to make sure I knew where it was. It says:

    The loop starts here:
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    But mine says:

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php $custom_fields = get_post_custom(); //custom fields ?>

    I'm using Blix, and that's the default code. Being the php novice that I am, what do the differences mean? Could it be affecting other things that I'm experiencing, like not being able to delete comments or pages?

  2. Root
    Member
    Posted 9 years ago #

    What this means if we have some posts, and while we work thru them, execute the function get post custom; once per post; and each time put the returned data in a variable (store) called $custom fields.

  3. davincim
    Member
    Posted 9 years ago #

    Thanks. So I take it that changing this code is not uncommon? I ask only because I get the feeling The Loop is a special thing and should be handled with care (not sure where I got that, but thought it's pretty important).

  4. Kafkaesqui

    Posted 9 years ago #

    This:

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    is equivalent to The Loop as found in the installed themes and on Codex. The php tags enclosing the post functions (<?php ?>) are there to allow PHP to be included in an HTML document, and if you remove them, you'll see the bare code is the same.

  5. Root
    Member
    Posted 9 years ago #

    Well the loop has its own mysteries. But like everything else in the end the urge to hack becomes irresistable. Backup your file and get stuck in. Codex is good.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags