jasonjasonjason on "how to prevent browser from scrolling to the top of the page on post navigation?"

ساخت وبلاگ

good evening,

i hope this is a very simple problem to fix, because i have been entirely unable to find anyone else asking how to solve it! so i assume that it's some simple mistake i'm making, that everyone else is clever enough to see immediately :

i am building a WP that uses Pages as the primary holder for content, and each Page has an index of all Posts of the same category as the page is talking about.

at the bottom of the Page is the first Post of the correct category, and that's where my problems start. when i click to view the next Post, the entire browser window scrolls all the way to the top of the Page, instead of refreshing the displayed Post.

how do i stop this scrolling? i want the browser window to stay where it is, and load the content for the next Post into the exact same place as the content from the previous Post.... without refreshing the rest of the screen.

i suspect my problem is that i'm using multiple Loops on one page, and so the screen scrolls up to the first instance?

page.php structure is as follows :

<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'page' ); ?>
<?php endwhile; // End of the loop. ?> -- SOME CONTENT HERE --
<?php query_posts( '&post_type=post&category_name='.$slug.'&order=ASC' ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php $imgID4 = get_post_thumbnail_id($post->ID); $featuredImage4 = wp_get_attachment_image_src($imgID4, 'thumbnail' ); $imgURL4 = $featuredImage4[0]; list($width, $height, $type, $attr) = getimagesize($imgURL4);
?>
-- MORE CONTENT HERE --
<?php endwhile; else: ?> <p>Sorry, there are no posts to display</p>
<?php endif; ?>
<?php rewind_posts(); ?>
<?php query_posts('showposts=1&category_name='.$slug.'&post_type=post&order=ASC'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php $imgID = get_post_thumbnail_id($post->ID); $featuredImage = wp_get_attachment_image_src($imgID, 'full' ); $imgURL = $featuredImage[0]; php list($width, $height, $type, $attr) = getimagesize($imgURL);
?>
-- STILL MORE CONTENT HERE --
<?php endwhile; else: ?> <p>Sorry, there are no posts to display</p>
<?php endif; ?>
<?php get_footer(); ?>

as you can see, i basically have three references to the Loop going on here, and i have a strong feeling that is what's causing the problem :)

any advise is appreciated!

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 36 تاريخ : شنبه 28 فروردين 1395 ساعت: 2:07