Created
July 23, 2012 03:05
-
-
Save amaxwell01/3161834 to your computer and use it in GitHub Desktop.
Custom Post Previous and Next functionality
This file contains 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 | |
/* | |
Template Name: Portfolio | |
*/ | |
function curPageURL() { | |
$pageURL = 'http'; | |
if ($_SERVER["HTTPS"] == "on") { | |
$pageURL .= "s"; | |
} | |
$pageURL .= "://"; | |
if ($_SERVER["SERVER_PORT"] != "80") { | |
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; | |
} else { | |
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; | |
} | |
return $pageURL; | |
} | |
if ( have_posts() ) { | |
while ( have_posts() ) { | |
the_post(); | |
$postID = get_the_ID(); | |
} | |
} | |
wp_reset_query(); | |
$wp_query = new WP_Query( array( | |
'post_type' => 'gallery', | |
'posts_per_page' => 1000 | |
)); | |
if( have_posts() ) { | |
$i = 0; | |
while( $wp_query->have_posts()) { | |
$wp_query->the_post(); | |
$links[$i] = get_permalink(); | |
$i++; | |
} | |
} | |
wp_reset_query(); | |
wp_reset_postdata(); | |
$currentURL = curPageURL(); | |
if( count($links) > 0 ) { | |
$commaSeparated = implode(',', $links) . $currentURL; | |
$linksCount = count($links) - 1; | |
for( $i=0; $i <= $linksCount; $i++ ) { | |
if( $links[$i] == $currentURL ) { | |
$previousItemNumber = $i - 1; | |
$currentItemNumber = $i; | |
$nextItemNumber = $i + 1; | |
break; | |
} | |
} | |
if( strlen( $links[$previousItemNumber] ) > 0 ) { | |
$previousLink = '<a id="previousGallery" href="' . $links[$previousItemNumber] . '" target="_self">Previous</a>'; | |
} | |
else { | |
$nextLink = ''; | |
} | |
if( strlen( $links[$nextItemNumber] ) > 0 ) { | |
$nextLink = '<a id="nextGallery" href="' . $links[$nextItemNumber] . '" target="_self">Next</a>'; | |
} | |
else { | |
$nextLink = ''; | |
} | |
if( strlen( $links[$nextItemNumber] ) > 0 && strlen( $links[$previousItemNumber] ) > 0 ) { | |
$centerElement = '<div id="centerElement"></div>'; | |
} | |
else { | |
$centerElement = ''; | |
} | |
} | |
?> | |
<?php get_header(); ?> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script src="<?php bloginfo('template_url'); ?>/js/slides.min.jquery.js"></script> | |
<script> | |
$(function(){ | |
$("#slides").slides(); | |
}); | |
</script> | |
<article id="portfolioPage" class="page"> | |
<h3 class="pagetitle portfolioTitle"> | |
</h3> | |
<div id="galleryNavigation"> | |
<? echo $previousLink; ?> | |
<? echo $centerElement; ?> | |
<? echo $nextLink; ?> | |
</div> | |
<?php | |
$wp_query = new WP_Query( array( | |
'post_type' => 'page', | |
'posts_per_page' => 1, | |
'p' => $postID | |
)); | |
?> | |
<?php if (have_posts()) : ?> | |
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> | |
<div id="galleryContainer"> | |
<?php | |
$gallery_id = get_post_meta($post->ID, 'gallery', true); | |
if(empty($gallery_id)) | |
{ | |
$gallery = 1; | |
} | |
elseif(!empty($gallery_id)) | |
{ | |
$gallery = $gallery_id; | |
} | |
echo do_shortcode('[nggallery id=' . $gallery . ']'); | |
?> | |
</div> | |
<div class="content"> | |
<?php the_content(); ?> | |
</div> | |
<?php endwhile; endif; ?> | |
</article> | |
<div id="galleryItems"> | |
<?php | |
$wp_query = new WP_Query( array( | |
'post_type' => 'gallery', | |
'posts_per_page' => 100 | |
)); | |
?> | |
<?php if (have_posts()) : ?> | |
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> | |
<div class="galleryItem"> | |
<a href="<?php echo get_permalink(); ?>" target="_self" title="<?php the_title(); ?>"> | |
<?php if((get_post_meta($post->ID, "thumbnail", true))) { ?> | |
<img src="<?php echo get_post_meta($post->ID, 'thumbnail', true); ?>" height="100" width="150" /> | |
<?php } ?> | |
<span><?php the_title(); ?></span> | |
</a> | |
</div> | |
<?php endwhile; ?> | |
<?php else : ?> | |
<?php | |
endif; | |
wp_reset_query(); | |
?> | |
</div> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment