I use the normal pagination method in wordpress
<?php $i = 1 ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => "2", 'paged' => $paged, 'cat' => 26 );
query_posts($args);
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="art_1">
<h5><?php echo $i ?>. <?php the_title(); ?></h5>
<?php $i++; ?>
</div>
<?php endwhile; ?>
<div class="er">
<?php next_posts_link(); ?>
</div>
<div class="err">
<?php previous_posts_link(); ?>
It works fine but the problem is this pagination I use for listing out articles in a particular category ,now I have another category of articles in same page which needs pagination too.pagination of 1st should no affect the other and vice versa. Can anyone suggest me what should I do?
Use this hook after pagination..
<?php wp_reset_query(); ?>
Related
I have one custom loop in a custom homepage in WordPress that is pulling 4 posts with some banners in middle. All is working fine, however pagination always shows same posts. Is there a way for me to add pagination to this custom loop?
My index.php code:
<?php
query_posts(array(
'post_type' => 'post',
'showposts' => 4,
) );
?>
<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 3) : ?>
<!-- banners -->
<h1> <?php the_title(); ?> </h1>
<?php the_content(); ?>
<?php else : ?>
<h1> <?php the_title(); ?> </h1>
<?php the_content(); ?>
<!-- banners -->
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<p align="center"><?php posts_nav_link(); ?></p>
Inside your query_post array add this line:
'paged' => ( get_query_var('paged') ) ? get_query_var('paged') : 1,
and in settings -> reading set 4 posts per blog page.
This is my code and i want to add a class in second child in loop. please tell me how can i do it. i am new in wordpress.
<?php
$args = array(
'posts_per_page' => 3,
'post_type' => 'hosting_plan',
'order' => 'ASC'
);
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<div class="hostplbx /*here i want to add class on second child*/">
<h3><?php the_field('plan_name'); ?></h3>
<div class="hostprice">
<span class="hosprice"><b class="rs"><?php the_field('plan_price'); ?></b> per month</span>
<span class="plandetail"><?php the_field('tag_line'); ?></span>
</div>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
You could use a simple iterator variable -- some sample code you can alter to apply to your template:
$counter = 1;
if ( have_posts() ) : while ( have_posts() ) : the_post();
if($counter == 2) echo "<div class='second_child_class'>content goes here</div>";
else echo "<div>content goes here</div>";
$counter++;
endwhile; endif;
please don't give a negative feed like always and instead tell me the mistake.
I have a blog.
can i make the homepage display a summary of an article instead of the whole article?
if yes then where or how can i do it?
I have this pre-set in one of my WordPress sites. Here is what this looks like and it is in Appearance/Editor/Posts Page (home.php)
<div class="post-content">
<?php $content = get_the_content(); ?>
<?php echo wp_trim_words(strip_tags($content), 30); ?>
</div>
<a class="blog-post-read-more" href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>"><?php echo esc_html( get_theme_mod( 'relia_blog_read_more', __( 'Read More', 'relia' ) ) ); ?></a>
</div>
So what this does is it will strip the words up to 30, wp_trim_words. And below that is the how to insert Read More.
Here are some links for you to check out:
https://codex.wordpress.org/Excerpt
https://codex.wordpress.org/Customizing_the_Read_More
Create one custom template that template you can assign your home page
/*
Template Name: Blog
*/
query_posts( array( 'post_type' => 'post', 'posts_per_page' => 6, 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ) ) );
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format()); ?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
wp_reset_postdata();
I am a new of wordpress. I have a problem with pagination when I click to the next post it shows "not found". I installed the plugin wp pagenavi, and I put code in my blog post . It shows the pagination, but I have a problem with the link to the next post. Example when I click to the next post it is show
Something went Wrong!
404
-->
You can see at: http://westecmedia.com/events/
And this is my code in event-page.php:
<div id="content-events">
<div id="head-event"><h3>EVENTS</h3></div>
<div id="main-event">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="part-event">
<div id="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div id="event-dess">
<h2><?php the_title(); ?></h2>
<p>
<?php
$content = get_the_content();
$content = strip_tags($content);
echo substr($content, 0, 300);
?>
</p>
<div id="read-more">Read More</div>
</div>
</div>
<div id="line-bottom"></div>
<?php endwhile; else: endif; ?>
<?php wp_pagenavi(); ?>
</div>
</div>
<?php get_footer(); ?>
Help me please ?
Maybe you missed the object here. You can try the code below:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => get_option('posts_per_page'),
'paged' => $paged,
'category_name'=>get_the_title(),
'post_status'=> array('publish', 'future')
);
query_posts($args);
instead:
<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
Similar questions have been asked but none seem to apply to my situation here.
I have two custom post-types built into a WP site. I created single-first_one.php to capture each of the first post-types. It works perfectly and the pagination I added works also.
The second post-type, I created single-second_one.php, and on this 'single' page, I'm displaying the current post, as well as below, the most recent 6 posts. Everything is showing as it should except my pagination links (in the single-second_one.php). The code is almost identical to that of the first 'single' template so I don't understand why it's not working. Any help?
<?php get_header(); ?>
<h1>Events</h1>
<section id=featured_post>
<?php $paged = (get_query_var('paged') && get_query_var('paged') > 1) ? get_query_var('paged') : 1; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h5 class=previous><?php previous_post_link('%link'); ?></h5>
<h5 class=next><?php next_post_link('%link'); ?></h5>
<article class="post-<?php the_ID(); ?>">
<div>
<?php if ( has_post_thumbnail()) : ?>
<?php the_post_thumbnail(); ?>
<?php endif; ?>
</div>
<h2><?php the_title(); ?></h2>
<h3><?php the_time('l F j'); ?></h3>
<?php the_content(); ?>
</article>
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</section>
<h1>Upcoming Events</h1>
<section id=other_posts>
<?php
$args = array('post_type' => 'event', 'showposts' => 6, 'order' => 'ASC', 'post_status' => 'future');
$loop = new WP_Query($args);
if ( have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();?>
<article class="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<h3><?php the_time('l F j'); ?></h3>
<?php html5wp_excerpt('events_page_listing'); ?>
</article>
<?php endwhile; else: ?>
<?php endif; ?>
</section>
I've gone to Options -> Permalinks, cached everything, taken out the second half section that calls the six recent posts, taken out single-first_one.php altogether, and nothing works. The 's for pagination on the second single page are empty.
EDIT
I've tried moving the next/previous calls around, after the endwhile, between endwhile and else, etc. Nothing is working. It's so bizarre because on the other single.php page, everything is setup the EXACT same way and is showing the next/prev posts links perfectly.
EDIT
I added the pagination argument but it's still not working.
You do not have any pagination arguments in the code ..
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 3,
'paged' => $paged
);
or
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('posts_per_page=3&paged=' . $paged);
or also something like
$paged = (get_query_var('paged') && get_query_var('paged') > 1) ? get_query_var('paged') : 1;