For some reason, when you click "Previous Posts" on my wordpress blog, the page URL changes, but the first ten posts are displayed again.
You can see the issue here: http://onedirectionconnection.com/ and then page two http://onedirectionconnection.com/page/2/#sthash.0SQiq9AP.dpbs (that's another thing - I'm not sure why that code is being added at the end of the following page's URL)...
Anyway, here is the code I'm using for my front page template saved in a file called front-page.php
<?php
/*
Template Name: Splash Page
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<div class="section-container">
<h1 class="section-title">Latest News</h1>
</div>
<?php $my_query = new WP_Query('showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h1 class="entry-title bottommargin big">
<?php the_title(); ?>
</h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
<div class="row">
<div class="col-md-12">
<footer class="row no-margin">
<div class="col-md-3 meta-entry">
Author: <br>
<?php the_author_link(); ?>
</div>
<div class="col-md-3 meta-entry">
Posted On:<br>
<?php the_time('F j, Y'); ?>
</div>
<div class="col-md-3 meta-entry">
Categorized:<br>
<?php echo get_the_category_list(', '); ?>
</div>
<div class="col-md-3 meta-entry-right">
Discussion:<br>
<?php comments_number(); ?>
</div>
</footer>
</div>
</div>
<?php endwhile; ?>
<div class="section-container">
<h1 class="section-title">More News</h1>
</div>
<?php
$custom_query = new WP_Query(array(
'posts_per_page' => 10,
'offset' => 1,
'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
));
?>
<?php while ($custom_query->have_posts()) : $custom_query->the_post(); ?>
<div class="row topmargin">
<div class="col-md-3 no-padding center">
<?php the_post_thumbnail('thumbnail', array('class' => 'img-thumbnail img-responsive')); ?>
</div>
<div class="col-md-9">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title">
<?php the_title(); ?>
</h1>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_excerpt(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'professional1d' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
<?php
// If comments are open or we have at least one comment, load up the comment template
if ( comments_open() || '0' != get_comments_number() )
comments_template();
?>
</div>
</div>
<footer class="row no-margin">
<div class="col-md-3 meta-entry">
Author: <br>
<?php the_author_link(); ?>
</div>
<div class="col-md-3 meta-entry">
Posted On:<br>
<?php the_time('F j, Y'); ?>
</div>
<div class="col-md-3 meta-entry">
Categorized:<br>
<?php echo get_the_category_list(', '); ?>
</div>
<div class="col-md-3 meta-entry-right">
Discussion:<br>
<?php comments_number(); ?>
</div>
</footer>
<?php endwhile; // end of the loop. ?>
<div class="center">
<?php posts_nav_link(); ?>
</div>
</main><!-- #main -->
</div><!-- #primary -->
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Everything seems pretty standard so I really have no clue what the issue is. If anyone could help me out with this issue, it would be greatly appreciated!
After comparing two - three post/pages of your blog. i think, it add the # tag at the end of url. this happen only after loading the entire page. which means it is added by one of your plugin. the plugin may be for "load fresh content from the server instead of the local browser cache"
so first deactivate the plugin you installed for this kind of features
Related
I am displaying posts and posts are limited to 10. And for rest, I have created pagination.
I have used a the_posts_pagination function. I used with and without arguments but my pagination is not working. It's always displaying the same set of posts
Please help me out.
Here is my code with pagination function I used.
<div class="row">
<?php
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('cat=-1,-4,-12');
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="col-md-12">
<div class="single-blog-post">
<div class="blog-post-cat"><?php the_category(', '); // Separated by commas ?></div>
<h3><?php the_title(); ?></h3>
<div class="blog-meta"><?php the_time('F j, Y'); ?><?php the_author_posts_link(); ?></div>
<div class="blog-details">
<div class="row">
<div class="col-md-6">
<div class="blog-thumbnail">
<!-- post thumbnail -->
<?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
<?php the_post_thumbnail(); ?>
<?php endif; ?>
<!-- /post thumbnail -->
</div>
</div>
<div class="col-md-6">
<div class="blog-content">
<?php the_content(); ?>
Read More
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php the_posts_pagination(); ?>
<?php wp_reset_postdata(); ?>
</div>
You need to add the paged parameter to your query based on the current page you are on. From what I can see in the above code, you're looping through the posts but don't have an offset so the posts are always starting from 0.
Check out the WP Query documentation.
<div class="row">
<?php
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query( 'cat' => '-1,-4,-12', 'paged' => get_query_var( 'paged' ) );
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="col-md-12">
<div class="single-blog-post">
<div class="blog-post-cat"><?php the_category(', '); // Separated by commas ?></div>
<h3><?php the_title(); ?></h3>
<div class="blog-meta"><?php the_time('F j, Y'); ?><?php the_author_posts_link(); ?></div>
<div class="blog-details">
<div class="row">
<div class="col-md-6">
<div class="blog-thumbnail">
<!-- post thumbnail -->
<?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
<?php the_post_thumbnail(); ?>
<?php endif; ?>
<!-- /post thumbnail -->
</div>
</div>
<div class="col-md-6">
<div class="blog-content">
<?php the_content(); ?>
Read More
</div>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php the_posts_pagination(); ?>
<?php wp_reset_postdata(); ?>
</div>
I've added the following to your query:
'paged' => get_query_var( 'paged' )
Try that out and it should display posts depending on the page you're currently on taking into account your actual query and arguments.
I am building a WordPress theme. I am having some trouble on commenting section. When showing comments it gets randomly post ID.
I have put the same code in 2 different places in the first place it TOP but by at BOTTOM its not working. Can anyone help me by telling why is this not working at bottom?!
Here is my single.php file
<?php get_template_part('/template-parts/standard-post-header'); ?>
<main role="main">
<!-- section -->
<section>
<div class="container background-color">
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if (has_post_video( isset($post_id) ) != null) {
// Featured VIDEO -->
get_template_part('/template-parts/featured-video-post');
// END Featured VIDEO -->
} else { ?>
<!-- Featured Image -->
<?php $header_type = get_post_meta(get_the_id(), 'meta-box-dropdown', true); ?>
<?php if ($header_type == 'Slider') {
// SLIDER Header
get_template_part('/template-parts/featured-slider-post');
?>
<?php } else {
// SLIDER Header
get_template_part('/template-parts/featured-normal-post');
} ?>
<!-- END Featured Image -->
<?php } ?>
<div class="container container-post-color">
<div class="content">
<?php the_content(); ?>
<?php edit_post_link(); ?>
</div>
</div>
<?php
global $post;
echo $post->ID;
?>
<ol class="commentlist">
<?php
//THIS WORKS!!!
$comments = get_comments(array(
'post_id' => $post->ID,
'status' => 'approve'
));
wp_list_comments(array(
'per_page' => 10,
'reverse_top_level' => false
), $comments);
?>
</ol>
<!-- Post Navigation -->
<div class="container container-post-color top-space" style="padding-left: 0px; padding-right: 0px;">
<div id="left-side"><?php previous_post_link(); ?></div>
<div id="right-side"><?php next_post_link(); ?></div>
<?php echo wp_link_pages(); ?>
</div>
<!-- Tags -->
<div class="tags-area">
<?php echo the_tags(); ?>
</div>
<!-- Related Articles -->
<?php get_template_part('/template-parts/related-articles'); ?>
<!-- Coments Part -->
<?php //get_template_part('/template-parts/comments'); ?>
<?php
global $post;
echo $post->ID;
?>
<ol class="commentlist">
<?php
//THIS DOES NOT WORKS!!! WHY?!
$comments = get_comments(array(
'post_id' => $post->ID,
'status' => 'approve'
));
wp_list_comments(array(
'per_page' => 10,
'reverse_top_level' => false
), $comments);
?>
</ol>
</article>
<!-- /article -->
</div>
<!-- END of Container-Fluid -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<div class="container background-color">
<h1 class="black mastheading-post"><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h1>
</div>
</article>
<!-- /article -->
<?php endif; ?>
</section>
<!-- /section -->
</main>
<!-- INSTAGRAM -->
<?php get_template_part('/template-parts/instagram'); ?>
<?php get_footer(); ?>
related-articles.php
<div class="container container-post-color" style="padding-left: 0px; padding-right: 0px;">
<div class="random">
<ul>
<?php $posts = get_posts('orderby=rand&numberposts=4'); foreach($posts as $post) { ?>
<div class="col-md-3 padding-zero">
<li>
<div class="random-thumb">
<?php the_post_thumbnail('full'); ?>
</div>
<div class="random-title">
<h1 class="black mastheading"><?php the_title(); ?></h1>
</div>
<div class="black iltalica"><?php echo excerpt(25); ?></div>
<div class="category">
<div class="random-category">
<h5><?php echo the_category();?></h5>
</div>
</div>
</li>
</div>
<?php } ?>
</ul>
</div>
</div>
So first off, since you are in the loop, everywhere you've used global $post; ... $post->ID you should be able to use get_the_ID() instead.
Second, I strongly suspect the problem is your template part /template-parts/related-articles probably messes-up the main loop. I suggest you look at that file and see if it's itself looping on a selection of posts - chances are it is not doing it cleanly, in a way that can be re-used inside the main loop.
You can add that file's code to your question if you need help figuring it out.
UPDATE
Ok, so indeed, you need to reset the loop data after the related-articles loop:
...
<?php
}
wp_reset_postdata(); // <----- add this after your loop
?>
</ul>
...
Hope this helps!
I created my own template in WordPress, but the loop entries does not work. I would like to entries work on one of the subpages. I also added entries.
This is my code of my subpage. Please help me. I don't know what is wrong. I added a picture under the code.
<?php include 'header.php'; ?>
<main class="subpage-blog">
<div class="subpage-banner">
<div class="container">
<h3>BLOG SIDEBAR</h3>
<div class="breadcrumbs">
</div>
</div>
</div>
<aside class="side-menu col-md-4">
<div class="search">
<h4>Search blog</h4>
<input type="text" value="Search">
</div>
<!-- .search -->
<div class="categories">
<h4>Blog Categories</h4>
<ul class="categories-blog-ul">
<li>Inspirtation</li>
<li>Work</li>
<li>Tech</li>
<li>Creative</li>
</ul>
</div>
<!--.categories-->
<div class="recent-posts">
<h4>Recents posts</h4>
<ul>
</ul>
</div>
<!-- .recent-posts-->
<div class="tags-spot">
<h4>Tags</h4>
<div class="tag"></div>
</div>
<!-- .tags-spot-->
</aside>
<!-- .side-menu-->
<article class="content">
<div class="container">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="news-box">
<div class="news-list-content">
<a href="">
<h3><?php the_title(); ?></h3>
<?php the_content('czytaj dalej'); ?>
</a>
</div>
<!-- .news-list-content-->
<div class="image-box-news">
<img src="<?=get_template_directory_uri(); ?>/images/ikona-wpisu.png" alt="" />
</div>
</div>
<!-- .news-box-->
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
<!-- .container-->
</article>
<!-- .content-->
</main>
<?php include 'footer.php'; ?>
The problem is that:
if (have_posts()) : while (have_posts()) : the_post();
is using the current page's have_posts query.. That means that it probably will just show whatever that current page template's content would be.
Instead, you'll want to create an entirely new query object and call these functions on it like so:
<?php
$the_query = new WP_Query( array('posts_per_page' => 10 ) ); //Create our new custom query
if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="news-box">
<div class="news-list-content">
<h3><?php the_title(); ?></h3>
<?php the_content('czytaj dalej'); ?>
</div>
<!-- all your other markup goes here.... -->
</div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php wp_reset_postdata(); //Restore the original postdata for this page, if needed later ?>
when you go to:
http://dageniusmarketer.com/
you will see the posts have 2 images. I'm trying to remove the one on the bottom.
I initially added
<?php the_post_thumbnail( $size, $attr ); ?>
for the main post image, as I wasn't getting the placement I wanted, which was ABOVE the post statistics. Now that I have it above the statistics, I still have the original image, and I want to remove it.
I'm trying to play with the class .wp-image,
but that isn't giving me any sort of luck. I just want to remove the 2nd duplicate image underneath the statistics and keep whatever other images I may wish to write into my post body in the future. How do I do this?
edit: here is my php code:
<?php get_header(); ?>
<div id="main">
<div id="content">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- item -->
<div class="item entry" id="post-<?php the_ID(); ?>">
<div class="itemhead">
<h1>
<?php the_title(); ?>
</h1>
<?php the_post_thumbnail( $size, $attr ); ?>
<div class="postStatsContainer">
<div class="postViews">100 Views</div>
<div class="slash"></div>
<div class="postShares">100 Shares</div>
<div class="slash"></div>
<div class="postComments">100 Comments</div>
<div class="slash"></div>
<div class="date"><?php the_time('M jS, Y') ?></div>
</div>
<div style="clear: both"></div>
<!--<div class="readMore_Container">-->
<?php the_content('Read More »'); ?>
<div class="postCounter">
<i class="fa fa-pencil-square-o fa-2x"></i>#200
</div>
<div class="metadata" style="clear:both;">
<div class="TagIcon"></div>
Filed under
<span class="category"><?php the_category(', ') ?></span> |
<?php edit_post_link('Edit', '', ' | '); ?>
<?php comments_popup_link('Comment (0)', ' Comment (1)', 'Comments (%)'); ?>
</div>
<div style="clear:both;"></div>
<div style="clear:both;"></div>
</div>
</div>
<!-- end item -->
<?php comments_template(); // Get wp-comments.php template ?>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Previous Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Next Entries »') ?></div>
<p> </p>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
<!-- end content -->
</div>
<div id="primary">
<?php include(TEMPLATEPATH."/l_sidebar.php");?>
</div>
<div id="secondary">
<?php include(TEMPLATEPATH."/r_sidebar.php");?>
</div>
<?php get_footer(); ?>
I created custom theme with WordPress and bootstrap and everything works fine except previous and next link in singe.php.
Here is my code:
<?php get_header(); ?>
<article>
<div class="container single-project">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<div class="row">
<div class=" col-md-4 col-lg-4 pull-right">
<header class="entry-header">
<h1 id="post-<?php the_ID(); ?>"><?php the_title();?></h1>
<hr>
</header><!-- .entry-header -->
</div>
<div class=" hidden-md hidden-lg"><hr></div>
<div class="col-md-4 col-lg-4"><?php the_content(); ?></div>
<?php previous_posts_link() ?>
<?php next_posts_link() ?>
</div> <!-- end of row -->
</div> <!-- end of container -->
<?php endwhile; endif; ?>
</article>
<?php get_footer(); ?>
Thanks in advance.
You have to move
<?php previous_posts_link() ?>
<?php next_posts_link() ?>
after
</article>
preferably inside some div so you can style it, like
<div class="navi">
<?php previous_posts_link() ?>
<?php next_posts_link() ?>
</div>
Found solution:
<?php previous_post('« « %', 'Previous Post', 'yes'); ?> |
<?php next_post('% » » ', 'Next Post', 'yes'); ?>
http://wpsites.net/web-design/previous-next-single-post-navigation-links-wordpress/