Home › Forums › WoodMart support forum › Blog Post Naviagtion
Blog Post Naviagtion
- This topic has 3 replies, 2 voices, and was last updated 3 years, 6 months ago by
Elise Noromit.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
July 20, 2020 at 6:35 am #212468
luan0409ParticipantHow to make blog post navigation on the same category?
I mean when i click next post, next post is from the same category
I dont want to use plugin cuz I have tested them all, nothing work well for me so far.
Just help me to change some code is good
July 20, 2020 at 2:26 pm #212686
Elise NoromitMemberHello,
Please add this code to the functions.php of the child theme:
function woodmart_posts_navigation() { ?> <div class="single-post-navigation"> <?php $next_post = get_next_post( true ); $prev_post = get_previous_post( true ); $archive_url = false; if ( get_post_type() == 'post' ) { $archive_page = get_option( 'page_for_posts' ); $archive_url = get_permalink( $archive_page ); } elseif ( get_post_type() == 'portfolio' ) { $archive_page = woodmart_tpl2id( 'portfolio.php' ); $archive_url = get_permalink( $archive_page ); } ?> <div class="blog-posts-nav-btn prev-btn"> <?php if ( ! empty( $next_post ) ) : ?> <div class="posts-nav-inner"> <a href="<?php echo get_permalink( $next_post->ID ); ?>"> <span class="btn-label"><?php esc_html_e( 'Newer', 'woodmart' ); ?></span> <span class="post-title"><?php echo get_the_title( $next_post->ID ); ?></span> </a> </div> <?php endif; ?> </div> <?php if ( $archive_url && 'page' == get_option( 'show_on_front' ) ) : ?> <div class="back-to-archive"> <a href="<?php echo esc_url( $archive_url ); ?>"><span class="woodmart-tooltip"><?php esc_html_e( 'Back to list', 'woodmart' ); ?></span></a> </div> <?php endif ?> <div class="blog-posts-nav-btn next-btn"> <?php if ( ! empty( $prev_post ) ) : ?> <div class="posts-nav-inner"> <a href="<?php echo get_permalink( $prev_post->ID ); ?>"> <span class="btn-label"><?php esc_html_e( 'Older', 'woodmart' ); ?></span> <span class="post-title"><?php echo get_the_title( $prev_post->ID ); ?></span> </a> </div> <?php endif; ?> </div> </div> <?php }
Best Regards
March 1, 2022 at 10:52 am #356592
b.brennerParticipantHello, I also miss a working post navigation within a category. I tried the code above in function.php but it doesn’t work.
March 2, 2022 at 10:59 am #356867
Elise NoromitMemberHello,
Please replace the code with this one:
function woodmart_posts_navigation() { woodmart_enqueue_inline_style( 'page-navigation' ); ?> <div class="single-post-navigation"> <?php $next_post = get_next_post(true); $prev_post = get_previous_post(true); $archive_url = false; if ( get_post_type() == 'post' ) { $archive_page = get_option( 'page_for_posts' ); $archive_url = get_permalink( $archive_page ); } elseif ( get_post_type() == 'portfolio' ) { $archive_page = woodmart_tpl2id( 'portfolio.php' ); $archive_url = get_permalink( $archive_page ); } ?> <div class="blog-posts-nav-btn prev-btn"> <?php if ( ! empty( $next_post ) ) : ?> <div class="posts-nav-inner"> <a href="<?php echo get_permalink( $next_post->ID ); ?>"> <span class="btn-label"><?php esc_html_e( 'Newer', 'woodmart' ); ?></span> <span class="wd-entities-title"><?php echo get_the_title( $next_post->ID ); ?></span> </a> </div> <?php endif; ?> </div> <?php if ( $archive_url && 'page' == get_option( 'show_on_front' ) ) : ?> <div class="back-to-archive"> <?php woodmart_enqueue_js_script( 'btns-tooltips' ); ?> <?php woodmart_enqueue_js_library( 'tooltips' ); ?> <a href="<?php echo esc_url( $archive_url ); ?>"><span class="wd-tooltip"><?php esc_html_e( 'Back to list', 'woodmart' ); ?></span></a> </div> <?php endif ?> <div class="blog-posts-nav-btn next-btn"> <?php if ( ! empty( $prev_post ) ) : ?> <div class="posts-nav-inner"> <a href="<?php echo get_permalink( $prev_post->ID ); ?>"> <span class="btn-label"><?php esc_html_e( 'Older', 'woodmart' ); ?></span> <span class="wd-entities-title"><?php echo get_the_title( $prev_post->ID ); ?></span> </a> </div> <?php endif; ?> </div> </div> <?php }
Best Regards
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to create new topics. Login / Register