• Resolved ewergreen

    (@ewergreen)


    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?

Viewing 6 replies - 1 through 6 (of 6 total)
  • where is the endwhile; of the loop in your code?

    can you paste the full code of that template? (please follow https://codex.www.ads-software.com/Forum_Welcome#Posting_Code for posting/pasting code)

    Thread Starter ewergreen

    (@ewergreen)

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

    (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: https://validator.w3.org/

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

    Thread Starter ewergreen

    (@ewergreen)

    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; ?>

    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?

    Thread Starter ewergreen

    (@ewergreen)

    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… .

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Breaking the loop breaks dynamic sidebar ability’ is closed to new replies.