When passing different posts_per_page values in functions.php number of posts shown changes but it doesnt load any other posts on scroll. Changing type to click doesn't do anything.
adding support in functions.php:
add_theme_support( 'infinite-scroll', array(
'type' => 'scroll',
'footer_widgets' => false,
'container' => 'content',
'render' => false,
'posts_per_page' => false,
) );
index.php:
<?php
get_header(); ?>
<div id="content">
<?php if (have_posts):
while (have_posts()) {
the_post();
get_template_part('content', get_post_format());
}
else:
echo '<p>No content found</p>';
endif; ?>
</div>
content.php:
<div class="post clearfix">
<div class="post-heading">
<h2><?php the_title(); ?></h2>
<h3><?php the_subtitle(); ?></h3>
</div>
<div class="post-content">
<?php the_content(); ?>
<?php if (is_single()): ?>
<div class="navigation clearfix">
<?php the_post_navigation( array(
'next_text' => 'Next',
'prev_text' => 'Previous',
'screen_reader_text' => ' '
)); ?>
</div>
<p>Main</p>
<?php endif; ?>
</div>
Related
How do I add pagination to this code? It currently shows latest articles.
Pagination can be after every 3 or 5 or 10 posts.
<?php
$the_query = new WP_Query( array(
'category_name' => $category_name,
'offset' => 1, //ignore the first 4 posts and show remaining
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 3,
'ignore_sticky_posts' => true,
));
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="home__full">
<div class="row">
<div class="col-md-3">
<small><?php the_time('F jS, Y') ?> • <?php echo reading_time(); ?> • <?php $cat = get_the_category(); echo $cat[0]->cat_name; ?></small>
</div>
<div class="col-md-6">
<h3><?php echo substr(get_the_title(),0,95); ?></h3>
<div class="home__latest--excerpt"><p><?php echo substr(get_the_excerpt(),0,140); ?></p></div>
</div>
<div class="col-md-3">
<a href="<?php the_permalink() ?>">
<?php if( !empty(get_the_post_thumbnail()) ) { ?>
<?php the_post_thumbnail('medium');?>
<?php } else { ?>
<img src="<?php echo get_template_directory_uri(); ?>/images/blog-thumbnail.png" alt="<?php echo the_title(); ?>" class="wp-post-image" />
<?php } ?>
</a>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php __('No News'); ?></p>
<?php endif; ?>
I created a custom blog template in my WPLMS Wordpress theme, with wp-query. But I'm unable to show the pagination. I tried to build a shortcode its working fine but in the last im unable to show my pagination.
//blog section 2
add_shortcode('da-blog', 'da_blog_post');
function da_blog_post($attr, $content = null){
$attributes = extract( shortcode_atts(array(
'title' => 'blog post',
'subtitle' => 'latest news',
), $attr) );
ob_start(); ?>
<section class="exthree_blog">
<div class="container">
<div class="row">
<div class="col-md-9">
<div class="all_exthree_blogs">
<div class="row">
<?php
$blogcontent = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 6,
'category__not_in' => array( 75 )
));
?>
<?php while($blogcontent->have_posts()) : $blogcontent->the_post(); ?>
<div class="col-md-4">
<div class="single_exthree_blog">
<div class="exthree_box">
<div class="exthree_box_img">
<!-- <img src="img/shutterstock_770159185.jpg" class="img-responsive"> -->
<a href="<?php echo get_permalink() ?>">
<?php if(has_post_thumbnail(get_the_ID())){ ?>
<?php echo get_the_post_thumbnail(get_the_ID(),'medium'); ?>
<?php }else{
$image = vibe_get_option('default_course_avatar');
?>
<img src="<?php echo vibe_sanitizer($image,'url'); ?>" />
<?php
}
$name = get_the_author_meta( 'display_name' );
?>
</a>
</div>
<div class="exthree_box_fortag">
</div>
<div class="boxxx">
<div class="exthree_box_title">
<h4><?php echo get_the_title(); ?></h4>
</div>
<div class="exthree_box_categor_list">
<?php echo get_the_category_list(); ?>
</div>
<div class="exthree_box_desc">
<p><?php echo get_the_excerpt(); ?></p>
</div>
<div class="exthree_box_button">
Continue<img src="http://localhost/gostudent/wp-content/uploads/2020/02/Layer-2.png">
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php echo "helooooooooooooooo"; ?>
<?php $big = 999999999; // need an unlikely integer
$links = paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $next_the_query->max_num_pages,
"type" => "list"
));
echo $links; ?>
</div>
</div>
</div>
</div>
</div>
</section>
<?php return ob_get_clean();
wp_reset_postdata();
}
I am using the below code to list the posts but there are more than 200 posts so i want to add pagination at the end.
<?php
// the query
$the_query = new WP_Query(array(
'category_name' => 'Reports',
'post_status' => 'publish',
));
?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="col-md-12 event_col">
<div class="col-md-2 event_date">
<span><?php echo the_post_thumbnail(null, 'medium');?></span>
</div>
<div class="col-md-7 event_venue">
<div class="titl">
<?php the_title(); ?>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php __('No News'); ?></p>
<?php endif; ?>
Every pagination link take me to the first page every time. I have tried with or without a plugin, but nothing works. It doesn't matter if I click on the Next button or the Prev button. It always takes me to the first page.
<?php
/*
Template Name: Notices & Circulars
*/
get_header(); ?>
<div class="banner-box">
<div class="wrap">
<div class="main-top">
<div class="main">
<h1><div class="titlepage"><?php the_title();?></div></h1>
<section class="content">
<?php
$args=array(
'cat'=> 14,
'posts_per_page' => 10,
'offset' => 5,
'paged' => get_query_var('page')
);
if ( have_posts() ) :
query_posts($args);
?>
<?php while(have_posts()):the_post();?>
<li style="list-style:none;">
<h3><font style="color:#666666;"><?php the_title(); ?></h3>
<?php
/***** Thumbnail ******/
the_post_thumbnail(
array(120, 90),
array(
'class' => 'thumbnail',
'alt' => 'post thumbnail',
'title' => 'my custom title'
)
);
/******* Thumbnail Ends ********/
the_content(__('Continue Reading'));?></font>
</li><hr /><?php
endwhile;
wp_pagenavi();
endif;
?>
</div>
</div>
</div>
<?php get_footer(); ?>
</div>
Please try this:
<?php
/*
Template Name: Notices & Circulars
*/
get_header(); ?>
<div class="banner-box">
<div class="wrap"><div class="main-top"><div class="main">
<h1><div class="titlepage"><?php the_title();?></div></h1>
<section class="content">
<?php
// Example for adding WP PageNavi to a new WP_Query call
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array('post_type' => 'post','cat'=> 14,'posts_per_page' => 10, 'paged' => $paged);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<li style="list-style:none;">
<h3><font style="color:#666666;"><?php the_title(); ?></h3>
<?php
/***** Thumbnail ******/
the_post_thumbnail(
array(120, 90),
array(
'class' => 'thumbnail',
'alt' => 'post thumbnail',
'title' => 'my custom title'
)
);
/******* Thumbnail Ends ********/
the_content(__('Continue Reading'));?></font>
</li><hr />
<?php
endwhile; ?>
<?php wp_pagenavi( array( 'query' => $loop ) ); ?>
</div></div></div>
<?php get_footer();?></div>
Hi all I am a new of wordpress,I use theme wordpress foundation, When I post sth, in my homepage can not see post ,and I try to write code in my homepage to get post but still can not see post,How can I do ,and here is my code:
page.php
<?php
/*
* Template Name: Page - Events Page
*/
?>
<?php get_header(); ?>
<div id="content-events">
<div id="head-event"><h3>EVENTS</h3></div>
<div id="main-event">
<?php
$args = array(
'cat' => '5',
'post_type' => 'post',
'posts_per_page' => 8,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
query_posts($args);
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;
?>
</div>
<div id="page-gina">
<?php
wp_pagenavi();
wp_reset_query(); // Restore global post data
?>
</div>
</div>
<?php get_footer(); ?>
Help me please !!!
<?php
/*Template Name: homepage template
*/
get_header();
?>
<?php
$args = array(
'cat' => '3',
'post_type' => 'post',
'posts_per_page' => 8,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
query_posts($args);
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;
?>
</div>
<?php get_footer(); ?>
Note: In dashboard,
i)Create page called Home,
ii)Same page right side template list shown assign homepage template,
ii)In Settings->Reading->Assign front page.