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();
}
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'm trying to list the posts related to the current taxonomy page but it shows me all the posts instead. When I output the current term name is correct so really I don't know why this happens. I'm pasting here the code if anyone can put me in the right direction.
<?php
$term = get_queried_object();
// Define the query
$args1 = array(
'post_type' => 'properties-for-sale',
'taxonomy' => $term->term_id
);
$query = new WP_Query($args1);
if ($query->have_posts()) { ?>
<h2 class="region-listing-title"><span class="thin-span">Luxury Properties for sale in</span> <?php echo $term->name; ?></h2>
<div class="swiper myswiper swiper-h">
<div class="swiper-wrapper">
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div class="swiper-slide">
<div class="favorite-button"><?php the_favorites_button($post_id, $site_id); ?></div>
<div class="swiper myswiper2 swiper-v">
<div class="swiper-wrapper">
<?php
$images = get_field('listing_gallery');
if ($images) : ?>
<?php foreach ($images as $image) : ?>
<div class="swiper-slide highlight-img" style="background-image: url(<?php echo $image['url']; ?>)"></div>
<?php endforeach; ?>
<?php endif;
?>
</div>
<div class="swiper-pagination"></div>
</div>
<div class="listing-informations">
<div id="lp-region-sale" class="listing-information-price">
<span><?php the_field('property_price'); ?> €</span>
</div>
<div>
<?php the_title(); ?>
</div>
<div class="listing-informations__listing-details">
<div class="listing-information-label"><span></span><?php the_field('number_of_bedrooms'); ?> Beds</div>
<div class="listing-information-label"><span></span><?php the_field('number_of_bathrooms'); ?> Baths</div>
<div class="listing-information-label"><span></span><?php the_field('interior_square_meters'); ?> Int Sqm</div>
<div class="listing-information-label"><span></span><?php the_field('lot_square_meters'); ?> Lot Sqm</div>
</div>
</div>
</div>
<?php endwhile;
} ?>
</div>
</div>
<?php wp_reset_postdata();
?>
Try with:
<?php
$term = get_queried_object()->term_id;
// Define the query
$args1 = array(
'post_type' => 'properties-for-sale',
'taxonomy' => $term
);
$query = new WP_Query($args1);
if ($query->have_posts()) { ?>
<h2 class="region-listing-title"><span class="thin-span">Luxury Properties for sale in</span> <?php echo $term->name; ?></h2>
<div class="swiper myswiper swiper-h">
<div class="swiper-wrapper">
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div class="swiper-slide">
<div class="favorite-button"><?php the_favorites_button($post_id, $site_id); ?></div>
<div class="swiper myswiper2 swiper-v">
<div class="swiper-wrapper">
<?php
$images = get_field('listing_gallery');
if ($images) : ?>
<?php foreach ($images as $image) : ?>
<div class="swiper-slide highlight-img" style="background-image: url(<?php echo $image['url']; ?>)"></div>
<?php endforeach; ?>
<?php endif;
?>
</div>
<div class="swiper-pagination"></div>
</div>
<div class="listing-informations">
<div id="lp-region-sale" class="listing-information-price">
<span><?php the_field('property_price'); ?> €</span>
</div>
<div>
<?php the_title(); ?>
</div>
<div class="listing-informations__listing-details">
<div class="listing-information-label"><span></span><?php the_field('number_of_bedrooms'); ?> Beds</div>
<div class="listing-information-label"><span></span><?php the_field('number_of_bathrooms'); ?> Baths</div>
<div class="listing-information-label"><span></span><?php the_field('interior_square_meters'); ?> Int Sqm</div>
<div class="listing-information-label"><span></span><?php the_field('lot_square_meters'); ?> Lot Sqm</div>
</div>
</div>
</div>
<?php endwhile;
} ?>
</div>
</div>
<?php wp_reset_postdata();
?>
Just use tax query.
<?php
$term = get_queried_object()->term_id;
$args = array(
'post_type' => 'properties-for-sale',
'tax_query' => array(
array(
'taxonomy' => $term->taxonomy,
'field' => 'term_id',
'terms' => $term->term_id
)
)
);
$query = new WP_Query( $args ); ?>
I created a Shortcode slider which gets ids of different pages and show display slider. Shordcode works fine but issue is that whenever i am copy past shortcode multiple times on same page/ template page it shows only first one.
This issue occurs only only when i past same type of shortcode but if i past any other shortcode on same page it works fine.
Here is my code
add_shortcode( 'objectx-pages-list', 'objectx_pages_list_func' );
function objectx_pages_list_func( $atts ) {
global $post;
ob_start();
extract( shortcode_atts( array('ids' => '1186'), $atts ) );
$id_array = explode(',', $ids);
$pages_query = new WP_Query( array(
'post_type' => 'page',
'post__in' => $id_array,
'order' => 'ASC',
'orderby' => 'title',
) );
if ( $pages_query->have_posts() ) { ?>
<div class="carousel-wrapper">
<div class="owl-carousel owl-theme carousel-1" id="carousel-rooms">
<?php while ( $pages_query->have_posts() ) : $pages_query->the_post();
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div <?php post_class('item'); ?> id="post-<?php the_ID(); ?>">
<div class="row">
<div class="col-md-7">
<div class="img-rooms">
<a href="<?php the_permalink(); ?>">
<img class="img-responsive wp-post-image" src="<?php echo $featured_image; ?>"></a>
</div>
</div>
<div class="col-md-5">
<div class="detail-rooms">
<h2 class="title-room "><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<?php $myvariable_pages = ob_get_clean();
wp_reset_postdata();
return $myvariable_pages;
}
}
Here is shortcode
[objectx-pages-list id="15,16,17"]
[objectx-pages-list ids="25,26,27"]
here you can see live example
http://objextheme.wpengine.com/
This one working fine
ROOFTOP PATIO & LOUNGE
but this is not working
This Week At Vertigo Sky Lounge
Please guide me where i am doing mistake. Thanks
add_shortcode( 'objectx-pages-list', 'objectx_pages_list_func' );
function objectx_pages_list_func( $atts ) {
global $post;
ob_start();
extract( shortcode_atts( array('ids' => '1186'), $atts ) );
$id_array = explode(',', $ids);
$pages_query = new WP_Query( array(
'post_type' => 'page',
'post__in' => $id_array,
'order' => 'ASC',
'orderby' => 'title',
) );
if ( $pages_query->have_posts() ) { ?>
<div class="carousel-wrapper">
<div class="owl-carousel owl-theme carousel-1" id="carousel-rooms">
<?php while ( $pages_query->have_posts() ) : $pages_query->the_post();
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div <?php post_class('item'); ?> id="post-<?php the_ID(); ?>">
<div class="row">
<div class="col-md-7">
<div class="img-rooms">
<a href="<?php the_permalink(); ?>">
<img class="img-responsive wp-post-image" src="<?php echo $featured_image; ?>"></a>
</div>
</div>
<div class="col-md-5">
<div class="detail-rooms">
<h2 class="title-room "><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<?php $myvariable_pages = ob_get_clean();
wp_reset_postdata();
return $myvariable_pages;
}
}
Here is the error i noticed. id="carousel-rooms" Id repeating on
same page. that is why only one time it runs perfect.
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>
I have a Wordpress Site or its Blog section I did a WP_Query post.
The loop is within a custom template its showing only one record while I have few post entries.
I think I have done correctly...
Please do let me why it is not looping the records.
<?php get_header();
?>
<div id="body">
<div class="container">
<div class="row-fluid">
<div class="span9">
<?php
$arr = array(
'post_type' => 'post',
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish'
);
$query = new WP_Query($arr);
if(count($query->posts) > 0):
$i = 0;
?>
<?php while($query->have_posts()): $i++;?>
<?php $query->the_post();
if(has_post_thumbnail(get_the_ID())){
$url_thumbnail = get_the_post_thumbnail(get_the_ID(), 'thumb_700x260', array('alt' => trim(get_the_title())));
$url_thumbnail_news = get_the_post_thumbnail(get_the_ID(), 'thumb_700x260', array('alt' => trim(get_the_title())));
} else {
$url_thumbnail = '<image src="'.get_template_directory_uri().'/images/no-thumbnail.jpg" title="No Thumbnail" alt="Free Nile Theme - Wordpress Theme from ThemeLead" />';
$url_thumbnail_news = '<image src="'.get_template_directory_uri().'/images/no-thumbnail-news.jpg" title="No Thumbnail" alt="Free Nile Theme - Wordpress Theme from ThemeLead" />';
}
?>
<?php if($i==1):?>
<div class="drop-shadow lifted"> <a class="nile-thumnail" href="<?php echo get_permalink(get_the_ID())?>" title="<?php the_title()?>"><?php echo $url_thumbnail;?></a> </div>
<div class="the_post">
<h2 class="bj-title"><a href="<?php echo get_permalink(get_the_ID())?>" title="<?php the_title()?>">
<?php the_title();?>
</a></h2>
<div class="bj-date">
<?php the_date();?>
<?php the_time();?>
</div>
<div class="bj-des">
<?php the_excerpt();?>
</div>
<a href="<?php the_permalink();?>" title="<?php the_title()?>" class="read-more">
<?php _e('Read more', APP_TD);?>
</a> </div>
<?php endif;?>
<?php endwhile;?>
<?php endif;?>
<?php // Reset Query
wp_reset_query(); ?>
<div class="navigation">
<div class="alignleft">
<?php previous_posts_link('« Previous') ?>
</div>
<div class="alignright">
<?php next_posts_link('More »') ?>
</div>
</div>
</div>
<div class="span3"> <?php echo get_default_sidebar();?> </div>
</div>
</div>
</div>
<?php get_footer();?>
Try removing the 'if($i==1)' and corresponding 'endif;' line