WordPress.org

Forums

Index Posts duplicating indefinitely. (12 posts)

  1. Shay
    Member
    Posted 3 years ago #

    I only know very basic php and am running into problems. I'm trying to have 7 individual divs (representing different main categories), within those divs, I'm trying to populate the post titles from those categories within it. For some reason after the last div, it repeats continually. Can anybody help me out please?

    The code is listed below is listed at: http://pastebin.com/KsENfvTi

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    don't use query_posts() within a loop;

    try to change this section to use 'get_posts' as well:

    <?php
                                                            query_posts('category_name=gluten-free-living&showposts=-1'); while(have_posts()) : the_post();
                                                            ?>
                                                            <li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
                                                            <?php endwhile; ?>

    and add:
    <?php wp_reset_postdata(); ?>
    before line 93
    <?php endwhile; ?>

  3. Shay
    Member
    Posted 3 years ago #

    It still duplicating: This is one of the div boxes, I have 7 of these, each with individual categories. I placed the "wp_reset_postdata90: ?> as well

    Code: http://pastebin.com/ehkquwCA

  4. alchymyth
    Forum Moderator
    Posted 3 years ago #

    please post the edited full code of the tempalte again using the pastebin http://pastebin.com/

    I didn't see 7 boxes in the first pastebin (?)

  5. Shay
    Member
    Posted 3 years ago #

    I only have 4 listed in the main code. I was making sure it worked properly before adding the other categories. I will add the 7 and repost

  6. Shay
    Member
    Posted 3 years ago #

    Here is the updated code with 6 categories (not seven, my apologies on the miscommunication)

    http://pastebin.com/k7fqzbDS

  7. alchymyth
    Forum Moderator
    Posted 3 years ago #

    the latest posted code does not repeat indefinitively - just as often as the number of posts per page setting.

    what page is this template used for?
    is it the index.php template?

    because the seven blocks are within the main loop, they will be repeated for as many posts per page are set in the settings - reading.

    ----
    try to use at the start of the loop:

    <?php while (have_posts()) : the_post(); ?>
    	<?php $count = 0;  $temp = $posts; ?>

    and at the end:

    <?php wp_reset_postdata();
    $posts = $temp; ?>
    <?php endwhile; ?>
  8. Shay
    Member
    Posted 3 years ago #

    It is in the index page. I currently have the posts per page in the settings - reading area to 4.

    I entered the information and its still repeating. I'm not sure if its an error elsewhere?

  9. alchymyth
    Forum Moderator
    Posted 3 years ago #

    its still repeating

    is it repeating 4 times or more ?

    what else do you need to show in the index page?
    there might be the need to pull your 7 blocks out of the loop.

    (also keep in mind that index.php is used as the general template if the more specialized templates are not in the theme - see http://codex.wordpress.org/Template_Hierarchy )

  10. Shay
    Member
    Posted 3 years ago #

    Yes it is. I changed the reading to show 1 post and syndication feed 1 as well and now its posting the 6 containers but with the page-navigation (21 pages). How would I remove the blocks out of the loop? Would you recommend creating a static index page with the blocks?

  11. Shay
    Member
    Posted 3 years ago #

    This actually worked: http://pastebin.com/qXerQr9D

    I removed the loop from the page.

    Thank you so much for your help!!

  12. alchymyth
    Forum Moderator
    Posted 3 years ago #

    Would you recommend creating a static index page with the blocks?

    that would make sense - to create a page template with the code;

    http://codex.wordpress.org/Pages#Page_Templates

    http://codex.wordpress.org/Creating_a_Static_Front_Page

Topic Closed

This topic has been closed to new replies.

About this Topic