Created
July 30, 2015 10:57
-
-
Save Loac-fr/eb22bc05ba334804878d to your computer and use it in GitHub Desktop.
Wordpress - Split gallery from post content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( get_post_gallery() ) : ?> | |
<div class="gallery-wrapper"> | |
<?php // build slider structure ?> | |
<div class=" slider-wrapper"> | |
<div class="slick-simple"> | |
<?php | |
$gallery = get_post_gallery( get_the_ID(), false ); | |
// get gallery images ids | |
$gids = explode( ",", $gallery['ids'] ); | |
/* Loop through all the image and output them one by one */ | |
foreach( $gallery['src'] as $index => $src ){ | |
?> | |
<div class="slide-wrapper align-center"> | |
<img src="<?php echo $src; ?>" class="slide-image" alt="Gallery image" /> | |
<p class="slide-caption"><?php echo( get_post_field('post_excerpt', (int)$gids[$index] )); ?></p> | |
</div> | |
<?php | |
} ?> | |
</div> | |
</div> | |
</div> | |
<div class="content-without-gallery"> | |
<div class="post-text-content"> | |
<h4 class="page_excerpt"><?php the_excerpt(); ?></h4> | |
<p><?php echo wpautop( strip_shortcodes( get_the_content() ) ) ?></p> | |
</div> | |
</div> | |
<?php | |
else : // if no gallery | |
?> | |
<section class="content-without-gallery"> | |
<div class="post-text-content"> | |
<h4 class="page_excerpt"><?php the_excerpt(); ?></h4> | |
<?php the_content(); ?> | |
</div> | |
</section> | |
<?php | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment