How to add default pagination to this code? - php

I have this code to get the latest 3 posts from "novels" category and display the content inside html tags.
<? $novels = get_option('of_novels') ?>
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('category_name=$novels&posts_per_page=3'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="sliderunit">
<?php the_post_thumbnail(); ?>
<div class="novelsslidertitle">
<div class="arrow-left"></div>
<img class="cross" src="<?php bloginfo('stylesheet_directory'); ?>/images/cross.png"/>
<?php the_title(); ?>
<h3>رواية</h3>
</div>
</div>
<?php endwhile;?>
What I need to know is how to add default next post in wordpress to this code?

Related

Page listing post_type pagination not working

I created a page template for join all posts from a specific post_type in one page, everything is working except the pagination. It show the right number of posts for page but, in this case, I have 8 posts and it only show 5. I did some changes but without success. Any ideas?
<?php
/*
Template Name: News
*/
?>
<?php get_header(); ?>
<!-- begin colLeft -->
<div class="container">
<main id="main" class="container" role="main">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array('paged' => get_query_var('paged'), 'posts_per_page'=>5, 'post_type'=>'our-work', 'order' => 'ASC'))
?>
<br><br><br>
<!--header-->
<div class="page-header">
<img src="www.wtk.com/img/3428245.png">
</div>
<div class="inform">
Display text here
</div>
<br>
<div>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="news-title">
<h3><?php the_title(); ?></a></h3>
</div>
<div class="news-box">
<?php the_post_thumbnail(); ?>
<?php the_excerpt(); ?>
Read more →
</div>
<br><br>
<?php endwhile;?>
<?php if (function_exists("emm_paginate")) {
emm_paginate();
} ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e('Not found'); ?></p>
<?php endif; ?>
</div>
</div>
<!-- end colleft -->
<?php get_footer(); ?>
I can see in your code you have 'posts_per_page' => 5. That would explain why you are seeing only 5 posts on the page.

Wordpress pagination system

I have a problem with my pagination system (wordpress). It's on my search page (display results), currently, the search system include only 2 post types, and the search system works fine, but clearly impossible to create a pagination system. I just want to create a simple previous and next page nav with the number of the current page.
<div class="contenu cont-menu fixed-cont aff">
<div class="page p-spe">Résults :
<span class="blue"><?php the_search_query(); ?></span></div>
<div class="nombre"><?php global $wp_query; echo ' ' .
$wp_query->found_posts . ' Result(s)'; ?></div>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<article class="article-menu">
<div class="article-menu a-m-sp">
<a href="<?php the_permalink(); ?>">
<span class="rollover r2"> </span>
<?php the_post_thumbnail(array(226,150)); ?>
</a>
<div class="right p-special">
<h2 class="h2-article-menu h2-ma"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a></h2>
<p class="date"><?php the_time('j F Y'); ?></p>
<?php the_excerpt(); ?>
Know more
</div>
</div>
<div class="sep sp-s"> </div>
</article>
<?php endwhile; ?>
<nav class="nav-pages">
<?php previous_posts_link('« Previous') ?>
<span class="nombre-pages"><?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
echo $paged.' / '.$wp_query->max_num_pages;
?></span>
<?php next_posts_link('Next »') ?>
</nav>
<?php
$wp_query = null;
$wp_query = $temp; // Reset
?>
<?php else : ?>
<div class="aucun-resultat">
<?php _e( 'No results' ); ?>
</div>
<?php endif; ?>
<?php
get_footer();
?>
So i add the pages nav just after the endwhile of the search results. I don't know why my system doesn't work. I'm a wordpress beginner, thank you for your help. Bernard
You don't need a custom query for this. Just add paginate_links() which generates pagination with arrows and numbers (can be configured to display as you wish).
http://codex.wordpress.org/Function_Reference/paginate_links
I update my post, because I made a pagination for 1 post type and It works fine. But now I would like to do a pagination of 2 post types. How i can change this code to make it works ?
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=4&post_type=dossiers'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>

Wordpress first post only on first page different then others

Got the next code to get the first Wordpress post on only the first page to be different. But it doesn't work. Looked at other questions and answers but there doesn't seem to be a good answer for this.
This is what i've got but isn't working for me:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 5, 'paged' => $paged );
query_posts($args); ?>
<?php if (have_posts()) : ?>
<?php $postcount = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $postcount++; ?>
<?php if ($postcount == 1 && $paged == 1) : // if this is the first post & first page ?>
<div class="large-10">
<?php the_post_thumbnail('large'); ?>
</div>
<?php else : //if this is NOT the first post ?>
<div class="large-6 columns">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="portfolio">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('large'); ?>
<span><h6><?php the_title(); ?></h6></span>
</a>
</div>
</article>
</div>
<?php endwhile; ?>
<?php endif; ?>
I get this syntax error "unexpected T_ENDWHILE" but can't figure out why.
Does anyone know how to properly get this done?
Thanks in advance!
Joeri
It looks like you don't have an endif for that inner if. Perhaps should be:
<?php if ($postcount == 1 && $paged == 1) : // if this is the first post & first page ?>
<div class="large-10">
<?php the_post_thumbnail('large'); ?>
</div>
<?php else : //if this is NOT the first post ?>
<div class="large-6 columns">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="portfolio">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('large'); ?>
<span><h6><?php the_title(); ?></h6></span>
</a>
</div>
</article>
</div>
<?php endif; ?>

Custom page template pagination not working when permalink structure is changed

I created a page template at http://www.durgeshsound.com/gallery/
Here my pagination buttons are not working. this issue arises when permalink format is http://www.testsite.com/sample-post/
But when I set permalink format to default for example http://testsite.com/?p=123 then it starts working
and creates a working pagination link like this http://www.durgeshsound.com/?page_id=81&paged=2.
I want this format http://www.testsite.com/sample-post/ in the links.
here is what i tried for custom page template
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('post_type=gallery&posts_per_page=9&paged=' . $paged); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
?>
<?php the_post_thumbnail('large'); ?>
<?php the_title( ); ?>
<?php
endif;
endwhile; endif;
?>
<?php kriesi_pagination(); ?>
<?php get_sidebar('gallery'); ?>
<?php get_footer(); ?>
Please help.
Below is custom Page : Replace $cat with your resp. ID
<ul class="clearfix">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$recentPosts = new WP_Query();
$recentPosts->query("cat=$cat&showposts=10&paged=".$paged); ?>
<?php if($recentPosts){ ?>
<?php if ( $recentPosts->have_posts() ): while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<li id="post-<?php the_ID(); ?>" <?php post_class('interview-list'); ?>>
<div class="video-thumb">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php if(has_post_thumbnail()) {
the_post_thumbnail(array(500,393));
}else {
echo '<img src="'.get_bloginfo("template_url").'/images/no-image.jpg" width="500px" height="393px"/>';
}
?> </a>
</div>
<div class="image-con">
<div class="int-title">
<?php the_title(); ?>
</div>
</div>
</li>
<?php endwhile; ?>
<?php else: ?>
<h2 class="post-title">No Photos</h2>
<?php endif; ?>
<div class="older-link"><?php next_posts_link('« Older Entries', $recentPosts->max_num_pages) ?></div>
<div class="newer-link"><?php previous_posts_link('Newer Entries »') ?></div>
<?php } ?>
</ul>

Wordpress Pagination showing same posts on all pages

On this page here, I'm using the following php code to show the posts:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($args);
if( have_posts() ) :?>
<?php twentyeleven_content_nav( 'nav-above' );?>
<?php
$withThumb = 5;
while ( have_posts() ) : the_post();
if ($withThumb-- > 0) { ?>
<div class="post-thumb-title">
<?php the_post_thumbnail(array(632,305));?>
<p class="thumb-title2"><?php the_title(); ?></p>
<p class="news-date"><?php the_time('F jS, Y') ?></p>
<div id="post-excerpt">
<?php the_excerpt(); ?>
</div>
</div>
<?php } else { ?>
<div class="post-title">
<p class="thumb-title2">
<?php the_title(); ?>
</p>
</div>
<?php } ?>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>
The issue is that if you click on "Older Posts", it shows the same posts and not the older ones.
It does the same when you open the 3rd page, 4th page and so on.
How do I fix this?
Thanks
You need to add the page number to the arguments of the query_posts() call.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args['paged'] = $paged;
query_posts($args);
See the documentation.
Note: If you've already defined $args and as a string not an array, you'll want to concatenate &paged=page_number_here, instead of adding a new key-value pair.

Categories