Skip to content

Commit

Permalink
feat: Post navigation
Browse files Browse the repository at this point in the history
Next/Previous links for Single Post.

#307
  • Loading branch information
stefan-cotitosu committed Jan 15, 2019
1 parent dff411c commit 180e200
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 4 deletions.
16 changes: 16 additions & 0 deletions assets/scss/elements/blog/_single.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@
display: flex;
}

.nv-content-wrap .post-navigation {
display: flex;
justify-content: space-between;

.previous,
.next {
a {
text-decoration: none;
}
}

.next {
align-self: end;
}
}

.nv-content-wrap .page-numbers {
justify-content: center;
margin: $spacing-xs auto;
Expand Down
7 changes: 5 additions & 2 deletions inc/customizer/options/layout_single_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ private function control_content_order() {
$order_default_components = array(
'title-meta',
'thumbnail',
'post-navigation',
);

$components = array(
'title-meta' => __( 'Title & Meta', 'neve' ),
'thumbnail' => __( 'Thumbnail', 'neve' ),
'title-meta' => __( 'Title & Meta', 'neve' ),
'thumbnail' => __( 'Thumbnail', 'neve' ),
'post-navigation' => __( 'Post navigation', 'neve' ),
);

$this->add_control(
Expand Down Expand Up @@ -86,6 +88,7 @@ public function sanitize_post_elements_ordering( $value ) {
$allowed = array(
'thumbnail',
'title-meta',
'post-navigation',
);

if ( empty( $value ) ) {
Expand Down
17 changes: 17 additions & 0 deletions inc/views/pluggable/pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Pagination extends Base_View {
public function init() {
add_filter( 'neve_filter_main_script_localization', array( $this, 'filter_localization' ) );
add_action( 'neve_do_pagination', array( $this, 'render_pagination' ) );
add_action( 'neve_post_navigation', array( $this, 'render_post_navigation' ) );

add_action( 'wp_ajax_infinite_scroll', array( $this, 'infinite_scroll' ) );
add_action( 'wp_ajax_nopriv_infinite_scroll', array( $this, 'infinite_scroll' ) );
Expand Down Expand Up @@ -57,6 +58,7 @@ public function filter_localization( $data ) {
public function render_pagination( $context ) {
if ( $context === 'single' ) {
$this->render_single_pagination();

return;
}

Expand Down Expand Up @@ -88,6 +90,21 @@ private function render_single_pagination() {
);
}

/**
* Render single post navigation links
*/
function render_post_navigation() {
$prev_format = '<div class="post-navigation"><div class="previous">%link</div>';
$next_format = '<div class="next">%link</div></div>';

$prev_link = esc_html__( 'PREVIOUS', 'neve' );
$next_link = esc_html__( 'NEXT', 'neve' );

previous_post_link( $prev_format, $prev_link );
next_post_link( $next_format, $next_link );
}


/**
* Infinite scroll ajax callback function.
*/
Expand Down
12 changes: 12 additions & 0 deletions style-rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,18 @@ article {
display: flex;
}

.nv-content-wrap .post-navigation {
display: flex;
justify-content: space-between;
}
.nv-content-wrap .post-navigation .previous a,
.nv-content-wrap .post-navigation .next a {
text-decoration: none;
}
.nv-content-wrap .post-navigation .next {
align-self: end;
}

.nv-content-wrap .page-numbers {
justify-content: center;
margin: 10px auto;
Expand Down
2 changes: 1 addition & 1 deletion style-rtl.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion style.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions template-parts/content-single.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
do_action( 'neve_before_content', 'single-post' ); ?>
<div class="nv-content-wrap entry-content">
<?php the_content(); ?>
<?php do_action( 'neve_post_navigation' ); ?>
<?php do_action( 'neve_do_pagination', 'single' ); ?>
</div>
<?php
Expand Down

0 comments on commit 180e200

Please sign in to comment.