Ready to get started?Download WordPress


Where do I find the loop? (21 posts)

  1. medes
    Posted 9 years ago #

    Don't know where to put this question.

    How do I place another function inside a php-loop?

    A "comment-counter" inside a loop of "latest posts".

    Where do I find this loop? I feel like I've tried to place the code everywhere.
    And is it the whole code, or just til function-call I have to place in the loop?

  2. Mark (podz)
    Support Maven
    Posted 9 years ago #


    Codex has all the info on The Loop :)

  3. Kafkaesqui

    Posted 9 years ago #


    For 1.5 users, the absolute beginning of a post Loop is here--consider it the green light for posts:

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

    The logic of this line works like this: "Do we have posts to do something with? Well if we do, for each post..." This could be considered The Loop Proper, in that this is where a post's components are displayed. A comment counter would definitely go in here.

    The Loop continues on with a Yield sign put in so WordPress can stop and think:

    <?php endwhile; else : ?>

    This is asking "If we haven't any posts based on what was queried, what then should we do?" Typically an error message would go here.

    Then, finally, the Stop sign for The Loop:

    <?php endif; ?>

  4. medes
    Posted 9 years ago #

    The counter is the write in like this:

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

    or ?

  5. medes
    Posted 9 years ago #

    Don't understad it.... :-(

    I use this:

    ...and this...:

    But where do I put the last one, if I want it to count comments for each post....?

  6. Kafkaesqui

    Posted 9 years ago #

    It can go anywhere in The Loop, but note this shows the # for all comments on your site (and will work outside The Loop as well as in):

    <?php mdv_comment_count(); ?>

    This would be used for comments only on a post (and in The Loop):

    <?php mdv_comment_count(FALSE); ?>

    See the (short) readme on the plugin:


  7. pdberger
    Posted 9 years ago #

    I've been driving myself crazy with this question for more than one week now. I understand what I am looking for, but I don't understand where I am supposed to look for The Loop? Is it in one of the theme files? If so, which one? The stylesheet? The header template? I'm sorry for posting what might seem like an idiotic question, but it's the only way I will learn :)

  8. Kafkaesqui

    Posted 9 years ago #

    Places to find The Loop (in 1.5) are in a theme's templates:

    - index.php
    - single.php
    - home.php
    - archive.php
    - category.php
    - page.php
    - author.php

    Not all themes will have all these templates (or need them), but each type of template listed will make use of The Loop. One additional template to be concerned with:

    - comments.php

    The loop here, however, is a bit different. It starts here:

    <?php foreach ($comments as $comment) { ?>

    "Yields" here:

    <?php } else { ?>

    And finally ends simply with:

    <?php } ?>

  9. pdberger
    Posted 9 years ago #

    Thank you so much for that. I appreciate the help.

  10. medes
    Posted 9 years ago #

  11. medes
    Posted 9 years ago #

    Still don't understand where to put the line for the counter, if i place it anywhere inside the <?php .... from the "recent posts", then it will not work on my site.
    If I put the <?php mdv_comment_count(FALSE); ?> after the <?php mdv_recent_posts(); ?> then it only counts for the first post...

  12. BradyDale
    Posted 7 years ago #

    I'm having a problem with the loop myself.
    If you feel like looking at my site, it's here...
    The loop at the bottom wants you to go the "Next Page" here:
    And previous page here:

    Only there is nothing at either of those places. The problem is the subdomain, I guess...
    Where it should go, at least for the next page, is here:
    and this works as well (and probably is easier... but who knows?)

    So how do I make that happen? I've looked around but I can't really figure it out. A problem I frequently find on the Codex is their is a description of the code you need but not where to find it. Hmm...

    Thank you so much for your help!


  13. BradyDale
    Posted 7 years ago #

    by the way, I just relooked at this post and the edges got cut off. What I posted did finish with "paged=2"

  14. moshu
    Posted 7 years ago #

    It seems you have a "fake" subdomain - so it will never work.
    By fake I mean it is redirected to a subfolder. WP won't work in that way.

  15. BradyDale
    Posted 7 years ago #

    I don't know much, but my instinct tells me that's not right.
    If bradydale.thistoowillpass.com
    effectively just looks at
    (which it does)
    isn't it simply just a matter of changing some of the code so it keeps looking at iterations of that?
    ...php?paged=2, etc.???

  16. moshu
    Posted 7 years ago #

    If bradydale.thistoowillpass.com
    effectively just looks at
    (which it does)

    That's the problem.
    A real, normal subdomain "looks at"

    Now, you have once:
    the redirect for your fake subdomain
    and secondly the two URI values set in the Options > General.

    If all those things point in 3 different directions (URLs) WP gives up.

  17. BradyDale
    Posted 7 years ago #

    Could I set up a page an index page that redirected you to another page that it would work in?

    I guess, though, what I really want to know is where do I go to try plugging in different values to make it work.

    I'm sure I can make it work somehow, I just need to know how to start messing with it. I'm at work now, so I'll try to go home and read the codex from the beginning and sort it out, but I feel like with some experimentation I can find a workable solution...

  18. moshu
    Posted 7 years ago #

    Get rid of the subdoamin redirect - that's THE workable solution.

  19. BradyDale
    Posted 7 years ago #

    accidentally posted twice.

  20. BradyDale
    Posted 7 years ago #

    Wow, now i've really messed it up. I'm going to have to go home and work on this tonight.

  21. moshu
    Posted 7 years ago #

    I don't understand what is so complicated.
    (we should move this hole discussion in a new thread - it has NOTHING to do with the Loop, btw)

    I have a very similar setup:
    subdomain.domain.net/blog - where WP is installed in the blog folder.

    This is the URI I put in the admin > Options > General settings. For both fields!

    The subdomain is NOT redirected. Always stays as you see it above.
    The blog works perfectly... believe it or not :)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.