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 trialKelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsget_permalink not working on my home page
the_permalink links perfectly to my individuals posts in my blog page but fail to link to the post that l feature in my home page as the latest post. any ideas how l can reslove this guys?
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsthanks for the reply Chris Upjohn the code is been pasted belwo. Thanks again buddy
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointsthanks for the reply Chris Upjohn the code is been pasted belwo. Thanks again buddy
3 Answers
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 Pointscode in my home.php for the wordpress loop to display my post and working perfectly is as below
<aside <?php post_class('post'); ?>>
<?php if( get_the_post_thumbnail() ) : ?>
<figure><?php the_post_thumbnail('large'); ?></figure>
<?php endif; ?>
<h3><?php the_title(); ?></h3>
<p>Posted on <?php the_time('F j, Y'); ?></p>
<p><?php echo strip_tags( get_the_excerpt() ); ?></p>
<a href="<?php the_permalink(); ?>" class="more">More <span>+</span></a>
</aside>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no pages found.' ); ?></p>
<?php endif; ?>
<div class="read-more"><a href="#">Read More <br /> <span>+</span></a>
Code in my page.php which is not working as expected is as below
<?php
query_posts( 'posts_per_page= 1' );
?>
<h2>Latest News</h2>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<aside>
<p><q><?php echo substr(get_the_excerpt(),0,120); ?>...</q></p>
<p class="txt"><a href="<?php the_permalink(); ?>" class="more">View Post ></a>
</p>
<?php if( get_the_post_thumbnail() ) : ?>
<figure><?php the_post_thumbnail('large'); ?></figure>
<?php endif; ?>
<a href="<?php echo get_permalink( 27 ); ?>" class="more">Go to news ></a>
</aside>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no pages found.' ); ?></p>
<?php endif; ?>
Zac Gordon
Treehouse Guest TeacherHi,
It looks like you're using two different approaches on the page.php page:
get_permalink( 27 );
and
the_permalink()
Are either ones working?
Kelvin Atawura
Front End Web Development Techdegree Student 19,022 PointsHi Zac Gordon my bad l should have went into details in my post sorry. the get_permalink(27) is working perfectly and links to my home.php. however the idea was for the_permalink to link to the individual post that l featured but not functioning asuch.
Chris Shaw
26,676 PointsSorry for the lengthy delay, there's no code issues within the loop that I can see, the only thing I don't see it wp_reset_query()
which is required after the loop when using query_posts()
and/or WP_Query
.
Aside from that everything seems to be in order.
Chris Shaw
26,676 PointsChris Shaw
26,676 PointsHi Kelvin,
Could you please post the code you have for your homepage, thanks.
https://teamtreehouse.com/forum/posting-code-to-the-forum