WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Breaking the loop breaks dynamic sidebar ability (7 posts)

  1. ewergreen
    Member
    Posted 2 years ago #

    I'm using dynamic sidebars which are working great, except on a custom page where I had to break the below (loop):
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    ...and replace it with:

    <?php if (have_posts()) : ?>
    <html to display tables />
    <?php while (have_posts()) : the_post(); ?>
    <html to display rows />

    This seems to be enough to break the functionality. I've tried a number of solutions incl. calling my preferred dynamic sidebar directly, but then it still displays the default sidebar.

    Anyone had this issue before and found a solution?

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    where is the endwhile; of the loop in your code?

    can you paste the full code of that template? (please follow http://codex.wordpress.org/Forum_Welcome#Posting_Code for posting/pasting code)

  3. ewergreen
    Member
    Posted 2 years ago #

    The endwhile; is right after the part where I display the rows.
    Full code can be found on pastebin: http://pastebin.com/0GfjypiZ

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    (i don't care about tables too much, however ...)
    it seems you are opening a lot of td and tr tags (and other table tags) without closing them;

    what does the validator say to the html output of your page: http://validator.w3.org/

    is the html output of the sidebar visible when you 'View' 'Source' of your page in the browser?

  5. ewergreen
    Member
    Posted 2 years ago #

    Haha, don't like tables either, however: I'm showing my page content above the table and the table isn't used for layout purposes, but is used to describe a number of objects that have the same properties, so belongs in this grid.

    My code is valid when using the validator. When looking at the rendered code, the end-tags are in place. Just fyi:

    There are a number of HTML tags in HTML4 and HTML5 that do not require the use of a closing tag for valid HTML. The reason that most of these tags don't have a required end tag is because in most cases, the end tag is implied by the presence of another tag in the document.

    The HTML output of the default table is displaying correctly and without problems, as is it displayed correctly on my site.

    Removing all HTML code but the broken loop like below still gives me the same issue:

    <?php if (have_posts()) : ?>
         <?php while (have_posts()) : the_post(); ?>
              <p>hi</p>
         <?php endwhile; ?>
    <p>test</p>
    
    <?php endif; ?>
  6. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    I'm using dynamic sidebars which are working great, except on a custom page where I had to break the below

    This seems to be enough to break the functionality

    what exactly does break ?

    is there still a sidebar, but without being dynamic?

    or no sidebar?

    {edit: is that template part 'afterloop' the sidebar? try to add a wp_reset_query(); before that; just in case your sidebar relies on the original query which got distorted by your custom loop}

    can you post a link to your site, pointing to that custom page, to illustrate the problem?

  7. ewergreen
    Member
    Posted 2 years ago #

    Thank you so much alchymyth, wp_reset_query(); fixed the problem. So stupid of me, sometimes you just need an extra pair of eyes - or maybe brains in this case... .

Topic Closed

This topic has been closed to new replies.

About this Topic