Last active
August 29, 2015 14:13
-
-
Save srikat/d704a5633dc324434cf2 to your computer and use it in GitHub Desktop.
Adding links to previous and next entries that slide open to reveal titles in Genesis.
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
| //* Make Font Awesome available | |
| add_action( 'wp_enqueue_scripts', 'enqueue_font_awesome' ); | |
| function enqueue_font_awesome() { | |
| wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css' ); | |
| } | |
| add_action( 'wp_enqueue_scripts', 'sk_sitewide_non_handhelds_scripts' ); | |
| /** | |
| * Load js file having the code for pushing the prev/next links off screen and animating on hover. | |
| * | |
| * Context: Single Posts and 'movies' CPT's single entries, on desktops only. | |
| * | |
| * @author Sridhar Katakam | |
| * @link http://sridharkatakam.com/add-links-previous-next-entries-slide-open-reveal-titles-genesis/ | |
| */ | |
| function sk_sitewide_non_handhelds_scripts() { | |
| if ( is_singular( array( 'post', 'movies' ) ) && ! wp_is_mobile() ) { | |
| wp_enqueue_script( 'sitewide-non-handhelds', get_stylesheet_directory_uri() . '/js/sitewide-non-handhelds.js', array( 'jquery' ), '1.0.0', true ); | |
| } | |
| } | |
| add_action( 'genesis_loop', 'sk_fixed_cpt_nav' ); | |
| /** | |
| * Display links to previous and next entries. | |
| * | |
| * Context: Single Posts and 'movies' CPT's single entries, on desktops only. | |
| * | |
| */ | |
| function sk_fixed_cpt_nav() { | |
| if ( is_singular( array( 'post', 'movies' ) ) && ! wp_is_mobile() ) { | |
| // http://codex.wordpress.org/Function_Reference/get_adjacent_post | |
| // get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ) | |
| $prev_post = get_adjacent_post( false, '', true ); | |
| $next_post = get_adjacent_post( false, '', false ); ?> | |
| <div class="btn-wrap"> | |
| <?php if ( !empty( $prev_post ) ) { ?> | |
| <a class="prevBtn" href="<?php echo get_permalink( $prev_post ); ?>"><?php echo $prev_post->post_title; ?><i class="fa fa-chevron-left"></i></a> | |
| <?php } ?> | |
| <?php if ( !empty( $next_post ) ) { ?> | |
| <a class="nextBtn" href="<?php echo get_permalink( $next_post ); ?>"><i class="fa fa-chevron-right"></i><?php echo $next_post->post_title; ?></a> | |
| <?php } ?> | |
| </div> | |
| <?php | |
| } | |
| } | |
| add_action( 'genesis_after_entry', 'sk_custom_post_nav' ); | |
| /** | |
| * Display links to previous and next entries. | |
| * | |
| * Context: Single Posts and 'movies' CPT's single entries, on handhelds only. | |
| * | |
| */ | |
| function sk_custom_post_nav() { | |
| if ( wp_is_mobile() && is_singular( array( 'post', 'movies' ) ) ) { | |
| echo '<div class="prev-next-post-links">'; | |
| previous_post_link('<div class="previous-post-link">« %link</div>', '<strong>%title</strong>' ); | |
| next_post_link('<div class="next-post-link">%link »</div>', '<strong>%title</strong>' ); | |
| echo '</div>'; | |
| } | |
| } |
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
| jQuery(function( $ ){ | |
| var prevBtn_offset = $('.prevBtn').outerWidth() - ($('.prevBtn i').outerWidth(true) + parseFloat($('.prevBtn').css('padding-right'))); | |
| $('.prevBtn').css('left',-prevBtn_offset); | |
| $('.prevBtn').hover(function() { | |
| $(this).animate({'left':'0'}); | |
| },function() { | |
| $(this).animate({'left':-prevBtn_offset}); | |
| }); | |
| var nextBtn_offset = $('.nextBtn').outerWidth() - ($('.nextBtn i').outerWidth(true) + parseFloat($('.nextBtn').css('padding-left'))); | |
| $('.nextBtn').css('right',-nextBtn_offset); | |
| $('.nextBtn').hover(function() { | |
| $(this).animate({'right':'0'}); | |
| },function() { | |
| $(this).animate({'right':-nextBtn_offset}); | |
| }); | |
| }); |
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
| /* ## Previous and Next entry links | |
| --------------------------------------------- */ | |
| .site-container { | |
| position: relative; | |
| } | |
| .prevBtn, | |
| .nextBtn { | |
| display: block; | |
| position: fixed; | |
| top: 250px; | |
| padding: 20px; | |
| color: #fff; | |
| background: #333; | |
| } | |
| .prevBtn:hover, | |
| .nextBtn:hover { | |
| color: #fff; | |
| } | |
| .prevBtn i { | |
| margin-left: 12px; | |
| } | |
| .nextBtn i { | |
| margin-right: 12px; | |
| } | |
| .nextBtn { | |
| right: 0; | |
| } | |
| .prev-next-post-links { | |
| overflow: hidden; | |
| margin-bottom: 40px; | |
| } | |
| .previous-post-link { | |
| float: left; | |
| } | |
| .next-post-link { | |
| float: right; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment