Skip to content

Instantly share code, notes, and snippets.

@immanuelsun
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save immanuelsun/772da67cd82922f3b4ad to your computer and use it in GitHub Desktop.

Select an option

Save immanuelsun/772da67cd82922f3b4ad to your computer and use it in GitHub Desktop.

Revisions

  1. immanuelsun revised this gist Jul 26, 2014. 1 changed file with 52 additions and 49 deletions.
    101 changes: 52 additions & 49 deletions wp_carousel.php
    Original file line number Diff line number Diff line change
    @@ -1,65 +1,68 @@
    <!-- Featured Post Carousel -->

    <!-- The Query -->
    <?php
    $args = array(
    'post_type' => 'post',
    'category_name' => 'featured'
    );
    <!-- The Query -->
    <?php
    $args = array(
    'post_type' => 'post',
    'category_name' => 'featured'
    );

    $the_query = new WP_Query( $args );
    ?>
    $the_query = new WP_Query( $args );
    ?>

    <div id="featured-posts" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
    <div id="featured-posts" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">

    <!-- Start the Loop -->
    <?php
    if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
    $the_count = $the_query->current_post;
    ?>
    <!-- Start the Loop -->
    <?php
    if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
    $the_count = $the_query->current_post;
    ?>

    <li data-target="#featured-posts" data-slide-to="<?php echo $the_count; ?>" <?php if($the_count == 0): ?>class="active"<?php endif; ?> ></li>
    <li data-target="#featured-posts" data-slide-to="<?php echo $the_count; ?>" <?php if($the_count == 0): ?>class="active"<?php endif; ?> ></li>

    <!-- End the Loop -->
    <?php endwhile; endif; ?>
    </ol>
    <!-- End the Loop -->
    <?php endwhile; endif; ?>
    </ol>

    <?php rewind_posts(); ?>
    <?php rewind_posts(); ?>

    <!-- Wrapper for slides -->
    <div class="carousel-inner">
    <!-- Wrapper for slides -->
    <div class="carousel-inner">

    <?php
    if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
    $the_count = $the_query->current_post;
    <?php
    if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
    $the_count = $the_query->current_post;

    $attachment_id = get_post_thumbnail_id(get_the_ID());
    $attachment_meta = wp_prepare_attachment_for_js( $attachment_id );
    $attachment_id = get_post_thumbnail_id(get_the_ID());
    $attachment_meta = wp_prepare_attachment_for_js( $attachment_id );

    $image_url = $attachment_meta['url'];
    $image_caption = $attachment_meta['caption'];
    $image_alt = $attachment_meta['alt'];
    ?>
    $image_url = $attachment_meta['url'];
    $image_caption = $attachment_meta['caption'];
    $image_description = $attachment_meta['description'];
    $image_alt = $attachment_meta['alt'];

    <div class="item <?php echo $the_count; ?> <?php if($the_count == 0): ?>active<?php endif; ?>">

    <a href="<?php the_permalink(); ?>"><img class="carousel-image" src="<?php echo $image_url; ?>" alt="<?php echo $image_alt; ?>"></a>
    <div class="carousel-caption">
    <?php the_title(); ?>
    </div>
    </div>
    ?>

    <!-- End the Loop -->
    <?php endwhile; endif; ?>
    </div> <!--/ carousel-inner -->
    <div class="item <?php echo $the_count; ?> <?php if($the_count == 0): ?>active<?php endif; ?>">

    <a href="<?php the_permalink(); ?>"><img class="carousel-image" src="<?php echo $image_url; ?>" alt="<?php echo $image_alt; ?>"></a>
    <div class="carousel-caption">
    <h5><?php the_title(); ?></h5>
    <p><?php echo $image_description; ?></p>
    </div> <!--/ carousel-caption -->
    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#featured-posts" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
    </a>
    <a class="right carousel-control" href="#featured-posts" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
    </a>
    <!-- End the Loop -->
    <?php endwhile; endif; ?>
    </div> <!--/ carousel-inner -->

    <!-- Controls -->
    <a class="left carousel-control" href="#featured-posts" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
    </a>
    <a class="right carousel-control" href="#featured-posts" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
    </a>
    </div> <!--/ #featured-posts carousel slide -->
  2. immanuelsun revised this gist Jul 26, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions wp_carousel.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <!-- Featured Post Carousel -->

    <!-- The Query -->
    <?php
    <?php
    $args = array(
    'post_type' => 'post',
    'category_name' => 'featured'
    @@ -55,11 +55,11 @@
    <?php endwhile; endif; ?>
    </div> <!--/ carousel-inner -->

    <!-- Controls -->
    <!-- Controls -->
    <a class="left carousel-control" href="#featured-posts" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
    </a>
    <a class="right carousel-control" href="#featured-posts" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
    </a>
    </div> <!--/ #featured-posts carousel slide -->
    </div> <!--/ #featured-posts carousel slide -->
  3. immanuelsun created this gist Jul 26, 2014.
    65 changes: 65 additions & 0 deletions wp_carousel.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    <!-- Featured Post Carousel -->

    <!-- The Query -->
    <?php
    $args = array(
    'post_type' => 'post',
    'category_name' => 'featured'
    );

    $the_query = new WP_Query( $args );
    ?>

    <div id="featured-posts" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">

    <!-- Start the Loop -->
    <?php
    if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
    $the_count = $the_query->current_post;
    ?>

    <li data-target="#featured-posts" data-slide-to="<?php echo $the_count; ?>" <?php if($the_count == 0): ?>class="active"<?php endif; ?> ></li>

    <!-- End the Loop -->
    <?php endwhile; endif; ?>
    </ol>

    <?php rewind_posts(); ?>

    <!-- Wrapper for slides -->
    <div class="carousel-inner">

    <?php
    if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
    $the_count = $the_query->current_post;

    $attachment_id = get_post_thumbnail_id(get_the_ID());
    $attachment_meta = wp_prepare_attachment_for_js( $attachment_id );

    $image_url = $attachment_meta['url'];
    $image_caption = $attachment_meta['caption'];
    $image_alt = $attachment_meta['alt'];
    ?>

    <div class="item <?php echo $the_count; ?> <?php if($the_count == 0): ?>active<?php endif; ?>">

    <a href="<?php the_permalink(); ?>"><img class="carousel-image" src="<?php echo $image_url; ?>" alt="<?php echo $image_alt; ?>"></a>
    <div class="carousel-caption">
    <?php the_title(); ?>
    </div>
    </div>

    <!-- End the Loop -->
    <?php endwhile; endif; ?>
    </div> <!--/ carousel-inner -->

    <!-- Controls -->
    <a class="left carousel-control" href="#featured-posts" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
    </a>
    <a class="right carousel-control" href="#featured-posts" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
    </a>
    </div> <!--/ #featured-posts carousel slide -->