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 trialvictoriadinh
1,473 PointsMy nav won't work properly on my Portfolio page. It works just fine from all other pages, how do I troubleshoot this?
My nav won't work properly on my Portfolio page. It works just fine from all other pages, how do I troubleshoot this?
4 Answers
Lucas Santos
19,315 PointsTry and provide the code so we can better assist you, but it seems to me if you have wp_nav_menu
all set up in your header.php and you do not see your header in one specific page you probably forgot to include the header on that page using get_header();
Seems like that would be the problem but I wont know for sure unless you provide code.
victoriadinh
1,473 PointsHi Lucas,
Yes, I had checked for that first but it's in there.
Here is my page-portfolio.php code:
<?php
/*
Template Name: Portfolio Page
*/
?>
<?php get_header(); ?>
<section class="row">
<div class="small-12 columns text-center">
<div class="leader">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<?php endwhile; endif; ?>
</div>
</div>
</section>
<section class="row no-max pad">
<?php if( $query ->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
<div class="small-6 medium-4 large-3 columns grid-item">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>
</div>
<?php endwhile; endif; wp_rest_postdata(); ?>
</section>
<?php
$args = array(
'post_type' => 'portfolio'
);
$query = new WP_Query( $args );
?>
<?php get_footer(); ?>
Lucas Santos
19,315 PointsGive this a try and let me know if it works.
<?php
/*
Template Name: Portfolio Page
*/
?>
<?php get_header(); ?>
<section class="row">
<div class="small-12 columns text-center">
<div class="leader">
<?php
$args = array(
'post_type' => 'portfolio'
);
$query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<?php endwhile; endif; ?>
</div>
</div>
</section>
<section class="row no-max pad">
<?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
<div class="small-6 medium-4 large-3 columns grid-item">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>
</div>
<?php endwhile; endif; ?>
</section>
<?php get_footer(); ?>
Lucas Santos
19,315 PointsBy the way I do not understand why you are running 2 different queries? Are you trying to get your regular posts on your portfolio page and then display your portfolio images? If not I would only use one loop for this (Your second custom query) and get rid of the first loop.
Lucas Santos
19,315 PointsAlso forgot to mention this. If you need to use wp_rest_postdata();
use it inside your if statement. That was giving you some problems because it was outside your if statement. I believe that was the problem and some other mark up issue I saw in there. Just did not use wp_rest_postdata();
because I dont know what your going to do with your queries so i'll leave that to you. I would add it like this tho:
<?php endwhile; ?>
<?php wp_rest_postdata(); ?>
<?php endif; ?>
you can read more about that here if you would like.
Rich Bagley
25,869 PointsHi Victoria,
Can you post the nav code in your header.php please?
Also, quick side note, I notice you're using wp_rest_postdata()
when it should be wp_reset_postdata()
. Not necessarily the issue but just wanted to give you a heads up :)
-Rich
Agustin Grube
39,278 PointsYou have multiple loops on the same page. You should close out the first loop to move to the second.
But start from the beginning. Your page should look like this:
<?php
/*
Template Name: Portfolio Page
*/
?>
<?php get_header(); ?>
<section class="row">
<div class="small-12 columns text-center">
<div class="leader">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
</div>
</section>
<?php get_template_part('content', 'portfolio'); ?>
<?php get_footer(); ?>
victoriadinh
1,473 PointsThanks for answering. I am currently on "The Portfolio Homepage" tutorial and the code is still containing 2 loops...I'm sure we will clean that up in the next stage?
Regarding my nav not working, I fixed the below typo
<?php endwhile; endif; wp_rest_postdata(); ?>
to the proper
<?php endwhile; endif; wp_reset_postdata(); ?>
and also moved
<?php
$args = array(
'post_type' => 'portfolio'
);
$query = new WP_Query( $args );
?>
to below the first section. and everything works fine now. Probably just the typo?
Rich Bagley
25,869 PointsHi Victoria,
Glad you got it sorted :)
-Rich
Lucas Santos
19,315 PointsGood eye, use that so much I didn't even notice the rest reset typo.. glad you got it working :]