• Resolved WP-Rasp

    (@wp-rasp)


    I am not sure what I did but after experimenting with query_posts and get_post, the WP query is not working..

    <nav class="footernav">
                             <ul class="navi">
    <?php
      $footer_query = new WP_Query('cat=1');
     while($footer_query->have_posts()) : $footer_query->the_post();
    
    <li><a>"><?php the_title(); ?></a> </li>
     endwhile;
    wp_reset_postdata();
                            ?>
    
                         </nav>

    Ive had success with the query_post but started to change everything to WP query because I heard that’s what you should do for Multiple Loops. I get this error;

    Parse error: syntax error, unexpected '<' in C:\wamp\www\wp-content\themes\BLANK-Theme\footer.php on line 16

    Line 16 is the closing ul. Is it possible to change or damage the loop somehow?

Viewing 3 replies - 1 through 3 (of 3 total)
  • always switch between php tags and html;

    example:

    <nav class="footernav">
                             <ul class="navi">
    <?php
      $footer_query = new WP_Query('cat=1');
     while($footer_query->have_posts()) : $footer_query->the_post(); ?>
    
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li>
    <?php endwhile;
    wp_reset_postdata();
                            ?>
    </ul>
                         </nav>

    Thread Starter WP-Rasp

    (@wp-rasp)

    Thank you Sir! I just learned a lot.

    I see how you closed the endwhile; and reset_postdata in their own php tag.

    <?php endwhile;
    wp_reset_postdata();
                            ?>

    If I delete the ?php or don’t close it with the ?> I get errors.

    I’m reading this book(DIGWP) on WordPress and how the loop works and they are showing it without the <?php before the endwhile;

    VERY WEIRD!

    I just got one question..How do you properly close all query_post php tags? I got something like this

    <?php
    global $query_string;
    $posts = query_posts($query_string.'&cat=-9');
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    ...
    
    <?php endwhile; else:
    ...
    endif;
    wp_reset_query(); // reset the query
    ?>

    Is that right? Because in my book its showing like this

    <?php
    global $query_string;
    $posts = query_posts($query_string.'&cat=-9');
    if (have_posts()) : while (have_posts()) : the_post();
    ...
    endwhile; else:
    ...
    endif;
    wp_reset_query(); // reset the query
    ?>
    Thread Starter WP-Rasp

    (@wp-rasp)

    Thanks again. Resolved

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Did I change/damage the gloabl query?’ is closed to new replies.