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 trialmohamed samir
1,152 Pointsi have a problem ???
i need help
i now building site bootstrap to wordpress but i make it code for slideshow but my pic is not show on my web any one can help me ...... thx
2 Answers
Craig Watson
27,930 PointsHi I just finished this course yesterday and my featured image from post seemed to work fine, here is the code :)
<?php
$args = array(
'post_type' => 'post',
'category_name' => 'feature'
);
$the_query = new WP_Query( $args );
?>
<!-- Dynamic Carousel -->
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li data-target="#carousel-example-generic"
data-slide-to="<?php echo $the_query->current_post; ?>"
class="<?php if( $the_query->current_post == 0 ) : ?>active<?php endif; ?>">
</li>
<?php endwhile; endif; ?>
</ol>
<!-- //Close Indicators -->
<?php rewind_posts(); ?>
<!-- Wrapper for Slides -->
<div class="carousel-inner" role="listbox">
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<!-- Carousel Item Wrapper -->
<div class="item <?php if( $the_query->current_post == 0 ) : ?>active<?php endif; ?>">
<?php
$thumbnail_id = get_post_thumbnail_id();
$thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail-size', true );
$thumbnail_meta = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true );
?>
<a href="<?php the_permalink(); ?>"><img src="<?php echo $thumbnail_url[0]; ?>" alt="<?php echo $thumbnail_meta; ?>"></a>
<div class="carousel-caption">
<?php the_title(); ?>
</div>
</div>
<!-- //Close Item Wrapper -->
<?php endwhile; endif; ?>
</div>
<!-- //Close Wrapper for Slide -->
<!-- Carousel Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
<!-- //Close Carousel Controls -->
</div>
<!-- //Close Carousel -->
Hope this helps :)
mohamed samir
1,152 PointsThanks So much Craig but where the copy paste this code on front-page or what ???
Craig Watson
27,930 PointsThis was in the home.php for the blog page between
<?php get_header(); ?>
<!-- Container Opens Here But Closes in footer.php -->
<div class="container">
<div class="row">
<div class="col-md-8">
<!-- Heading of Page -->
<div class="page-header">
<h1><?php wp_title( '' ); ?></h1>
</div>
<!-- //Close Heading -->
<!-- // The Carousel Code Goes Here :) // -->
<!-- Open Loop -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article class="post">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p>
<em>
By <?php the_author(); ?>,
on <?php echo the_time( 'l, F jS, Y' ); ?>,
in <?php the_category( ', ' ); ?>
with <a href="<?php comments_link(); ?>"><?php comments_number(); ?></a>
</em>
</p>
<hr>
<?php the_excerpt(); ?>
</article>
<?php endwhile; else: ?>
<div class="page-header">
<h1>Oh no!</h1>
</div>
<p>No content seems to be registed to this page please check your Pages and Template Settings!</p>
<?php endif; ?>
<!-- //Close Loop -->
</div>
<!-- //Close Column -->
<!-- Get The Sidebar Content Widget from sidebar-blog.php -->
<?php get_sidebar( 'blog' ); ?>
</div>
<!-- //Close Row -->
</div>
<!-- //Close Container -->
<?php get_footer(); ?>
Hope this sorts it out be sure to check your category name against mine :)
Craig Watson
27,930 PointsCraig Watson
27,930 PointsOhh one thing i was getting messed up on when i was doing it..
in the args array be sure to check your spelling of the slug for category name I had wrote featured in the code at first and feature in the admin .... not good lol
Thanks
mohamed samir
1,152 Pointsmohamed samir
1,152 PointsThanks So much Craig but where the copy paste this code on front-page or what ???