Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Konrad Pilch
Konrad Pilch
2,435 Points

Whats wrong with this code?

It breaks , but it works when i delete the loop.

<aside class="col-xs-12 col-sm-12 col-md-3 margin-bottom-20-mobile">
   <div class="service-component">

      <?php
        if($post->post_parent) {
          $titlenamer = get_the_title($post->post_parent);
        }
        else {
          $titlenamer = get_the_title($post->ID);
        }
        ?>
        <h3 class="services-heading"><?php echo $titlenamer; ?> </h3>
        <ul class="list-unstyled vertical-services">
          <?php 
            $list_args = array(
               'post_type'        => 'services',
               'posts_per_page'   => -1
            );
            $list_query = new WP_Query( $list_args );


            // Loop
            if ( $list_query->have_posts() ) : while ( $list_query->have_posts() ) : $list_query->the_post(); ?>
            <li>
              <a href="<?php the_permalink();?>">
                <?php the_title(); ?>
                <span class="glyphicon glyphicon-menu-right service-arrow"></span>
              </a>
            </li>
            <?php else : ?>

          <?php endif; ?>
        </ul>
   </div>
</aside>

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Try this...

On closer inspection it looks like you hadn't closed your while loop inside the loop

<?php endwhile; else : ?>

So put this in where you have

<?php else : ?>
Konrad Pilch
Konrad Pilch
2,435 Points

One thing, you know when i press the link, it goes to permalink, and it shows me this http://wpsidki:8888/services/test-marketing-service/

which it should because i clicked on marketing services, and thats a service.

This is on my sidebar.

But it links me to a white page, why?

It displays the posts, but it doesnt show me anything.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

I can't be sure I have the right answer here but what sticks out to me is the -1 for your posts_per_page parameter that's inside your custom query?. Is this right?

Konrad Pilch
Konrad Pilch
2,435 Points

I took that off and put it, it has no difference.