Skip to content

Commit c07b363

Browse files
committed
add next and previous buttons to learn pages
1 parent 4a97726 commit c07b363

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

themes/learn.jquery.com/functions.php

+32
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,35 @@ function is_subpage() {
1010
return false; // ... the answer to the question is false
1111
}
1212
}
13+
14+
if ( version_compare( $wp_version, '3.5-alpha', '<' ) ) :
15+
add_filter( 'posts_where_paged', function( $where, $query ) {
16+
global $wpdb;
17+
if ( $menu_order = absint( $query->get( 'menu_order' ) ) )
18+
$where .= " AND $wpdb->posts.menu_order = " . $menu_order;
19+
return $where;
20+
}, 10, 2 );
21+
endif;
22+
23+
function get_next_prev_post() {
24+
global $post;
25+
$menu_order_prev = $post->menu_order - 1;
26+
$menu_order_next = $post->menu_order + 1;
27+
28+
$posts_prev= new WP_Query( array(
29+
'post_type' => 'page',
30+
'post_status' => 'publish',
31+
'menu_order' => $menu_order_prev
32+
) );
33+
34+
$posts_next= new WP_Query( array(
35+
'post_type' => 'page',
36+
'post_status' => 'publish',
37+
'menu_order' => $menu_order_next
38+
) );
39+
40+
return array(
41+
'prev' => count($posts_prev->posts) ? $posts_prev->posts[0] : NULL,
42+
'next' => count($posts_next->posts) ? $posts_next->posts[0] : NULL
43+
);
44+
}

themes/learn.jquery.com/page.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php get_header(); ?>
2-
2+
<?php $next_prev_arr = get_next_prev_post(); ?>
3+
34
<!-- body -->
45
<?php global $sidebar; ?>
56
<div id="body" class="clearfix <?php echo $sidebar; ?>">
@@ -14,6 +15,25 @@
1415
<h2>Suggestions, Problems, Feedback</h2>
1516
<a class="btn" href="<?php echo jq_get_github_url(); ?>"><i class="icon-github"></i> Open an Issue or Submit a Pull Request on GitHub</a>
1617

18+
19+
<div class='bottom-links'>
20+
<?php if (isset($next_prev_arr['prev'])): ?>
21+
<div class='prev'>
22+
<a href="<?php echo $next_prev_arr['prev']->guid; ?>">
23+
<i class="icon-chevron-left"></i>
24+
<?php echo $next_prev_arr['prev']->post_title; ?>
25+
</a>
26+
</div>
27+
<?php endif; ?>
28+
<?php if (isset($next_prev_arr['next'])): ?>
29+
<div class='next'>
30+
<a href="<?php echo $next_prev_arr['next']->guid; ?>">
31+
<?php echo $next_prev_arr['next']->post_title; ?>
32+
<i class="icon-chevron-right"></i>
33+
</a>
34+
</div>
35+
<?php endif; ?>
36+
</div>
1737
</div>
1838
<!-- /inner -->
1939

themes/learn.jquery.com/style.css

+22
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,25 @@ Template: jquery
6363
#body .inner .icon-github {
6464
color:#30b9f8;
6565
}
66+
#body .inner .bottom-links {
67+
background:lightGray;
68+
overflow:auto;
69+
padding:0px 20px;
70+
clear:left;
71+
}
72+
#body .inner .bottom-links i{
73+
}
74+
#body .inner .bottom-links a{
75+
text-decoration:none;
76+
}
77+
#body .inner .bottom-links .prev, #body .inner .bottom-links .next {
78+
color:gray;
79+
font-size:1.5em;
80+
line-height:2em;
81+
}
82+
#body .inner .bottom-links .prev {
83+
float:left;
84+
}
85+
#body .inner .bottom-links .next {
86+
float:right;
87+
}

0 commit comments

Comments
 (0)