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 trialjazib shahzad
Courses Plus Student 268 PointsSingle.php is not working
I added code in single.php but it isn't working.i added comments template func. but it is not showing it too. here is single.php code:
<?php get_header(); ?>
<section class="two-column row no-max pad">
<div class="small-12 columns">
<div class="row">
<!-- Primary Column -->
<div class="small-12 medium-7 medium-offset-1 medium-push-4 columns">
<div class="primary">
<?php if (have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article class="post">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<ul class="post-meta no-bullet">
<li class="author">
<span class="wpt-avatar small">
<?php echo get_avatar( get_the_author_meta( 'ID' ), 24 ); ?>
</span>
by <?php the_author_posts_link(); ?>
</li>
<li class="cat">in <?php the_category( ', ' ); ?></li>
<li class="date">on <?php the_time('F j, Y'); ?></li>
</ul>
<?php if( get_the_post_thumbnail() ) : ?>
<div class="img-container">
<?php the_post_thumbnail( 'large' ); ?>
</div>
<?php endif; ?>
<?php the_content(); ?>
<?php comments_template(); ?>
</article>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, nopages found.' ); ?></p>
<?php endif; ?>
</div>
</div>
<!-- Secondary Column -->
<div class="small-12 medium-4 medium-pull-8 columns">
<div class="secondary">
<h2 class="module-heading">Sidebar</h2>
</div>
</div>
</div>
</section>
<?php get_footer(); ?>
3 Answers
jazib shahzad
Courses Plus Student 268 PointsThanks! Actually when i open my blog page it shows my posts with title,content then pic when i click on post then it opens another page which have things as i want title, pic then content and finally comments section.i want that on blog page which now is on page when i open post.
Stanley Thijssen
22,831 PointsSo that means your single.php is working. You have to take a look the home.php template instead to get what you want.
jazib shahzad
Courses Plus Student 268 Pointsyeah. but couldn't find any bug
lassi
4,908 PointsHallo community, I speak french und german, my Englisch is not to well. But I need help. my single.php don´t work, I have a same single.php like a Teacher. please look at it and give me a solution.
<?php get_header(); ?>
<section class="two-column row no-max pad"> <div class="small-12 columns"> <div class="row"> <!-- Primary Column --> <div class="small-12 medium-7 medium-offset-1 medium-push-4 columns"> <div class="primary">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article class="post">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<ul class="post-meta no-bullet">
<li class="author">
<span class="wordpress_portfolio_theme-avatar small">
<?php echo get_avatar( get_the_author_meta('ID'), 24 ); ?>
</span>
by <?php the_author_posts_link(); ?>
</li>
<li class="cat">von <?php the_category( ','); ?></li>
<li class="date">am <?php the_time( 'F j, Y'); ?></li>
</ul>
<?php if( get_the_post_thumbnail() ) : ?>
<div class="img-container">
<?php the_post_thumbnail( 'large'); ?>
</div>
<?php endif; ?>
<?php the_content(); ?>
<?php the_comments_template(); ?>
</article>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts found.' ); ?></p>
<?php endif; ?>
</div>
</div>
<!-- Secondary Column -->
<div class="small-12 medium-4 medium-pull-8 columns">
<div class="secondary">
<h2 class="module-heading">Sidebar</h2>
</div>
</div>
</div>
</section>
<?php get_footer(); ?>
Stanley Thijssen
22,831 PointsStanley Thijssen
22,831 PointsHey Jazib,
Did you create a comments.php file? If you did then probably you didnt put any code inside this file so you dont see anything on your page because your including you comments.php file.
You can check if it works when you delete the comments.php file from your template. The default will be output by wordpress then.