How to customize owl carousel slider - php

I've added the owl carousel 2 (the most recent update) to my theme. I've added the carousel successfully. However, I have no control over customizing it. I've tried editing the owl-carousel.js file and I've tried editing my owl.carousel-init.js file, but neither of them give me the customizations I want. The main one being that I only want 5 owl items and there are currently 8. Have I added all of the correct files? This is the first theme I'm building, so I'm not 100% confident I did everything right. Can someone help spot the error I made, and help me customize it? Thanks in advance.
I set up my carousel.php file to show the most recent popular posts*
front-page.php
<?php
/*
* Template Name:
*/
get_header();
get_template_part ('inc/carousel');
$the_query = new WP_Query( [
'posts_per_page' => 14,
'paged' => get_query_var('paged', 1)
] );
if ( $the_query->have_posts() ) { ?>
<div id="ajax">
<?php
$i = 0;
$j = 0;
while ( $the_query->have_posts() ) { $the_query->the_post();
if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after... ?>
<div class="row">
<article <?php post_class( 'col-sm-12 col-md-12' ); ?>>
<div class="large-front-container">
<?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
</div>
<h2><a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-page-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part( 'front-shop-the-post' ); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</div>
</article>
</div>
<?php
} else { // Small posts ?>
<?php if($j % 3 === 0) echo '<div class="row">'; ?>
<article <?php post_class( 'col-md-4' ); ?>>
<?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?>
<h2><a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-page-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part( 'front-shop-the-post' ); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</div>
</article>
<?php $j++; if($j % 3 === 0) echo '</div>'; ?>
<?php
}
$i++;
}?>
</div>
<?php if(get_query_var('paged') < $the_query->max_num_pages) {
load_more_button();
}
}
elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();
get_footer();
carousel.php
<div class="owl-carousel">
<?php
$carousel_cat = get_theme_mod('carousel_setting','1');
$carousel_count = get_theme_mod('count_setting','4');
$month = date('m');
$year = date('Y');
$new_query = new WP_Query( array('posts_per_page' => $carousel_count, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC','monthnum'=>$month,'year'=>$year ));
?>
<?php if ( $new_query->have_posts() ) : ?>
<?php while ( $new_query->have_posts() ) : $new_query->the_post(); ?>
<div class="item">
<?php the_post_thumbnail('popular-posts'); ?>
<h2><a class="popular-category"
<?php
$categories = get_the_category();
$separator = ", ";
$output = '';
if ($categories) {
foreach ($categories as $category) {
$output .= '' . $category->cat_name . '' . $separator;
}
echo trim($output, $separator);
}
?></a></h2>
<p>
<a class="popular-excerpt" href="<?php the_permalink(); ?>"><?php echo get_the_excerpt(); ?></a>
</p>
</div>
<?php endwhile; wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, No Popular Posts Found ' ); ?></p>
<?php endif; ?>
</div>
owl.carousel-init.js
$(document).ready(function() {
$(".owl-carousel").owlCarousel({
autoPlay: 3000, //Set AutoPlay to 3 seconds
items : 4,
itemsDesktop : [1199,3],
itemsDesktopSmall : [979,3]
});
});
functions.php
unction templatename_add_owlcarousel() {
wp_enqueue_script ( 'jquery' );
wp_enqueue_script( 'owl-carousel-init', get_template_directory_uri() . '/js/owl.carousel-init.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/js/owl.carousel.js', array( 'jquery' ), false, true );
wp_enqueue_style( 'owlcarousel-style-theme', get_template_directory_uri() . '/css/owl.theme.css' );
wp_enqueue_style( 'owlcarousel-style', get_template_directory_uri() . '/css/owl.carousel.css' );
}
add_action( 'wp_enqueue_scripts', 'templatename_add_owlcarousel' );
footer.php
script src="<?php bloginfo('template_directory'); ?>/js/owl.carousel-init.js"></script>
<script src="<?php bloginfo('template_directory'); ?>/js/owl.carousel.js"></script>
<script src="<?php bloginfo('template_directory'); ?>/js/jquery.js"></script>
FILES IV'E ADDED
css/owl.carousel.css
css/owl.theme.css
js/owl.carousel.js

owl.carousel-init.js
$(document).ready(function() {
$(".owl-carousel").owlCarousel({
autoPlay: 3000, //Set AutoPlay to 3 seconds
responsive:{
0:{
items:1,
nav:true
},
600:{
items:2,
nav:false
},
1000:{
items:4,
nav:true,
loop:false
}
}
});
});
and in footer.php
<script src="<?php bloginfo('template_directory'); ?>/js/jquery.js"></script>
<script src="<?php bloginfo('template_directory'); ?>/js/owl.carousel.js"></script>
<script src="<?php bloginfo('template_directory'); ?>/js/owl.carousel-init.js"></script>
hope this helps..

Related

Post page pagination not working - wordpress WP-PageNavi

I am having trouble with wordpress post page with pagination. I have installed a pagination plugin (WP-PageNavi), and I have being able to print all my posts so far, but pagination just shows one page (the present one). How can I make pagination work properly?
<?php
// args query
$args = array(
'post_type' => 'post',
'order' => 'DESC'
);
// custom query
$recent_posts = new WP_Query($args);
// check that we have results
if($recent_posts->have_posts()) : ?>
<ul class="article_list">
<?php
// start loop
while ($recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
<li class="regular">
<a href="<?php echo get_permalink(); ?>">
<div class="text">
<p class="category"><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></p>
<h3 class="article_title"><?php echo mb_strimwidth(get_the_title(), 0, 80, '...'); ?></h3>
<p class="date"><?php echo get_the_date( 'Y-m-d' ); ?></p>
</div>
<div class="mask">
<img src="<?php the_post_thumbnail_url();?>" alt="" class="art_img">
</div>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif;
// reset query
wp_reset_postdata();
?>
<?php include($path.'libs/pagination.php'); ?>
Here is my pagination.php file:
<div class="pagination">
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
</div>
I guess you have put wp_pagenavi(); function to libs/pagination.php.
So, replace it with
wp_pagenavi(array( 'query' => $recent_posts ));
So, final code should look like,
<?php
// args query
$args = array(
'post_type' => 'post',
'order' => 'DESC'
);
// custom query
$recent_posts = new WP_Query($args);
// check that we have results
if($recent_posts->have_posts()) : ?>
<ul class="article_list">
<?php
// start loop
while ($recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
<li class="regular">
<a href="<?php echo get_permalink(); ?>">
<div class="text">
<p class="category"><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></p>
<h3 class="article_title"><?php echo mb_strimwidth(get_the_title(), 0, 80, '...'); ?></h3>
<p class="date"><?php echo get_the_date( 'Y-m-d' ); ?></p>
</div>
<div class="mask">
<img src="<?php the_post_thumbnail_url();?>" alt="" class="art_img">
</div>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif;
echo '<div class="pagination">';
if(function_exists('wp_pagenavi')) { wp_pagenavi(array( 'query' => $recent_posts )); }
echo '</div>';
wp_reset_postdata();
?>
I found the problem in my code:
I was not adding anything for the pagination in my query, so it was returning all my posts.
So I added a pagination logic to my custom query and it did work.
<?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$custom_args = array(
'post_type' => 'post',
'order' => 'DESC',
'posts_per_page' => 5,
'paged' => $paged
);
// custom query
$recent_posts = new WP_Query($custom_args);
// check that we have results
if($recent_posts->have_posts()) : ?>
<ul class="article_list">
<?php
// start loop
while ($recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
<li class="regular">
<a href="<?php echo get_permalink(); ?>">
<div class="text">
<p class="category"><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></p>
<h3 class="article_title"><?php echo mb_strimwidth(get_the_title(), 0, 80, '...'); ?></h3>
<p class="date"><?php echo get_the_date( 'Y-m-d' ); ?></p>
</div>
<div class="mask">
<img src="<?php the_post_thumbnail_url();?>" alt="" class="art_img">
</div>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif;
echo '<div class="pagination">';
if(function_exists('wp_pagenavi')) { wp_pagenavi(array( 'query' => $recent_posts )); }
echo '</div>';
wp_reset_postdata();
?>

How to correctly add in a row to bootstrap to fix grid system moving onto multiple lines

I am using bootstrap to display the posts on my front page. I have my posts alternate between 2 rows of 3 posts and 1 large post. Everything looked good except for the fact that I noticed that if there is a longer title or excerpt in one of the posts then the rest of the page would be messed up (example below). After researching I've noticed the best solutions are to use row and clear fix. However every time I try adding a div of row I seem to be placing it in incorrectly. (I had some help constructing my front-page.php so I don't know the correct way to add it in) Can anyone help me correctly add in a div row into my front-page.php? I would appreciate it a lot, I've been trying to find a solution for weeks!
I have tried looking at different solutions to questions on here but I still can't correctly change my own code. So if anyone can help at all it would be greatly appreciated.
how it should look...
how it looks when I have a post that has a title (or excerpt) that goes on to multiple lines...
as you can see example post 12 moves all the way over to the right (where it should be on the left) example post 13 and 14 are moved underneath.
my front-page.php
<?php
/*
* Template Name:
*/
get_header();
get_template_part ('inc/carousel');
$the_query = new WP_Query( [
'posts_per_page' => 14,
'paged' => get_query_var('paged', 1)
] );
if ( $the_query->have_posts() ) {
?>
<div id="ajax">
<?php
$i = 0;
while ( $the_query->have_posts() ) {
$the_query->the_post();
if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after...
?>
<article <?php post_class( 'col-sm-12 col-md-12' ); ?>>
<div class="large-front-container">
<?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
</div>
<h2><a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-page-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part( 'front-shop-the-post' ); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</div>
</article>
<?php
} else { // Small posts
?>
<article <?php post_class( 'col-md-4' ); ?>>
<?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?>
<h2><a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-page-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part( 'front-shop-the-post' ); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</div>
</article>
<?php
}
$i++;
}
?>
</div>
<?php
if(get_query_var('paged') < $the_query->max_num_pages) {
load_more_button();
}
}
elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();
get_footer();
You can create another variable $j = 0 and add row every 3rd small blog post.
<?php
/*
* Template Name:
*/
get_header();
get_template_part('inc/carousel');
$the_query = new WP_Query( [
'posts_per_page' => 14,
'paged' => get_query_var('paged', 1)
] );
if ($the_query->have_posts()) {
?>
<div id="ajax">
<?php
$i = 0;
$j = 0;
while ($the_query->have_posts()) {
$the_query->the_post();
if ($i % 7 === 0) { // Large post: on the first iteration and every 7th post after...
?>
<div class="row">
<article <?php
post_class('col-sm-12 col-md-12');
?>>
<div class="large-front-container">
<?php
the_post_thumbnail('full', array(
'class' => 'large-front-thumbnail'
));
?>
</div>
<h2><a class="front-page-post-title" href="<?php
the_permalink();
?>"><?php
the_title();
?></a></h2>
<p class="front-page-post-excerpt"><?php
echo get_the_excerpt();
?></p>
<div class="front-page-post-info">
<a class="moretext" href="<?php
the_permalink();
?>">Read more</a>
<?php
get_template_part('front-shop-the-post');
?>
<?php
get_template_part('share-buttons');
?>
<div class="front-comments"><?php
comments_popup_link('0', '1', '%', 'comment-count', 'none');
?></div>
</div>
</article>
</div>
<?php
} else { // Small posts
?>
<?php
if ($j % 3 === 0)
echo '<div class="row">';
?>
<article <?php
post_class('col-md-4');
?>>
<?php
the_post_thumbnail('full', array(
'class' => 'medium-front-thumbnail'
));
?>
<h2><a class="front-page-post-title" href="<?php
the_permalink();
?>"><?php
the_title();
?></a></h2>
<p class="front-page-post-excerpt"><?php
echo get_the_excerpt();
?></p>
<div class="front-page-post-info">
<a class="moretext" href="<?php
the_permalink();
?>">Read more</a>
<?php
get_template_part('front-shop-the-post');
?>
<?php
get_template_part('share-buttons');
?>
<div class="front-comments"><?php
comments_popup_link('0', '1', '%', 'comment-count', 'none');
?></div>
</div>
</article>
<?php
$j++;
if ($j % 3 === 0)
echo '</div>';
?>
<?php
}
$i++;
}
?>
</div>
<?php
if (get_query_var('paged') < $the_query->max_num_pages) {
load_more_button();
}
} elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();
get_footer();

only show load more button if there is something to load

I added a load more button with the plugin "easy load more" (https://wordpress.org/plugins/easy-load-more/). The button is working great except that it will still show up even if there are no more posts to display. I would like to hide the button if there are no more posts left to load. Does anyone have any suggestions for how I could do this? I've been stumped on this for weeks, I would really appreciate any help!
frontend.js
;(function ($) {
$(document).ready(function() {
$('.elm-button').on('click', function (e) {
e.preventDefault();
var $that = $(this),
url = $that.attr('data-href'),
nextPage = parseInt($that.attr('data-page'), 10) + 1,
maxPages = parseInt($that.attr('data-max-pages'), 10);
$that.addClass('is-loading');
if (url.indexOf('?') > 0) {
url += '&';
} else {
url += '?';
}
url += 'paged=' + nextPage;
$.ajax({
type : 'POST',
url : url,
dataType: 'text'
}).done(function (data) {
$that.removeClass('is-loading');
if ($(elm_button_vars.wrapper).length) {
$(elm_button_vars.wrapper).append($($.parseHTML(data)).find(elm_button_vars.wrapper).addBack(elm_button_vars.wrapper).html());
} else {
console.log('Please update Easy Load More settings with post list wrapper selector.');
}
if ( nextPage == maxPages ) {
$that.remove();
} else {
$that.attr('data-page', nextPage);
}
}).fail(function () {
console.log('Ajax failed. Navigating to ' + url + '.');
window.location.href = url;
});
return false;
});
});
}(jQuery));
and my front-page.php
<?php
/*
* Template Name:
*/
get_header();
get_template_part ('inc/carousel');
$the_query = new WP_Query( [
'posts_per_page' => 14,
'paged' => get_query_var('paged', 1)
] );
if ( $the_query->have_posts() ) { ?>
<div id="ajax">
<?php
$i = 0;
while ( $the_query->have_posts() ) { $the_query->the_post();
if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after... ?>
<article <?php post_class( 'col-sm-12 col-md-12' ); ?>>
<div class="large-front-container">
<?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
</div>
<h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<div class="front-post-info">
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</article><?php
} else { // Small posts ?>
<article <?php post_class( 'col-sm-6 col-md-4' ); ?>>
<div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div>
<a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</article>
<?php
}
$i++;
}?>
</div>
<?php if(get_query_var('paged') < $the_query->max_num_pages) {
load_more_button();
}
}
elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();
get_footer();
I don't know about that plugin, but on the AJAX Load More Plugin it adds a class of done to the load more button when there are no more posts, so you can hide it with javascript targeting that class. Does this plugin do something similar?

how to add ajax load more repeater template

I'm trying to add a load more button to my front page. I have my posts set up so that I have one post in a row, and then 3 posts in a row, another 3 posts in a row, and then 1,3,3,etc. I want to add the load more button after 14 posts. I've added the short code however now when I press the load more button the posts appear all wonky. I have figured out its because I never customized my repeater code. However, I can't figure out how to properly add my template to the repeater code since I had a lot of help writing the code for my front-page.php. If anyone can help me out I would really appreciate it.
The plugin I am using is - https://wordpress.org/plugins/ajax-load-more/faq/
my front-page.php
<?php
/*
* Template Name:
*/
get_header();
get_template_part ('inc/carousel');
$the_query = new WP_Query( [
'posts_per_page' => 14,
'paged' => get_query_var('paged', 1)
] );
if ( $the_query->have_posts() ) { ?>
<?php
$i = 0;
while ( $the_query->have_posts() ) { $the_query->the_post();
if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after... ?>
<article <?php post_class( 'col-sm-12 col-md-12' ); ?>>
<div class="large-front-container">
<?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
</div>
<h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</article><?php
} else { // Small posts ?>
<article <?php post_class( 'col-sm-6 col-md-4' ); ?>>
<div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div>
<a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</article>
<?php
}
$i++;
}
wp_reset_postdata();?>
</div>
<?php
}
else {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
echo do_shortcode( '[ajax_load_more id="ajax-load" post_type="post" posts_per_page="14" pause="true" scroll="false" button_label="LOAD MORE"]' );
get_footer();
I've asked the author for help and hist suggestion was to use Ajax Load More variables (https://connekthq.com/plugins/ajax-load-more/docs/variables/) so something like this...
if ( $alm_item % 7 === 0 ) { // Large posts
} else { // Small posts
}
so I have now tried the following for my repeater template but it still does not work...
<?php
/*
* Template Name:
*/
$the_query = new WP_Query( [
'posts_per_page' => 14,
'paged' => get_query_var('paged', 1)
] );
if ( $the_query->have_posts() ) { ?>
<div id="ajax-load">
<?php
$i = 0;
while ( $the_query->have_posts() ) { $the_query->the_post();
if ( $alm_item % 7 === 0 ) { // Large posts ?>
<article <?php post_class( 'col-sm-12 col-md-12' ); ?>>
<div class="large-front-container">
<?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
</div>
<h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</article><?php
} else { // Small posts ?>
<article <?php post_class( 'col-sm-6 col-md-4' ); ?>>
<div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div>
<a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
<a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
<?php get_template_part ('front-page-shop'); ?>
<?php get_template_part( 'share-buttons' ); ?>
<div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
</article>
<?php
}
$i++;
}?>
</div>
<?php if(get_query_var('paged') < $the_query->max_num_pages) {
}
}
elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();

Add post order to function (php)

How to add post order to this function? I would like to display most recent post from newest to oldest:
<?php
//Establish first post check variable
$first_post = true;
query_posts('category_name=blog&showposts=3');
while (have_posts()) : the_post(); ?>
<li>
<a href="<?php echo get_permalink($post->ID); ?>">
<p class="news_title"><?php $title = get_the_title(); echo wp_trim_words( $title , '4', $more = null ); ?></p></a>
<?php if($first_post) { ?>
<div class="post_skrot"><?php echo wp_trim_words( get_the_content(), $num_words = 8, $more = '... <a class="button_more" href="'. get_permalink($post->ID) . '">show more >> </a>' ); ?></div>
<?php } else { ?>
<div class="post_skrot"><a class="button_more" href="'.get_permalink($post->ID).'">show more>> </a></div>
<?php } ?>
</li>
<?php
//Change value of $first_post
$first_post = false;
endwhile;
wp_reset_query(); ?>
I try add
&orderby=date&order=ASC
but it doesn't work.
Whole code:
<div id="sliders-2-3">
<div class="elementy-oferty">
<div class="slider-4">
<div class="border-video">
<div class="content-slider-4">
<div class="blog_top_title">Blog</div>
<ul>
<?php
//Establish first post check variable
$first_post = true;
$args = array(
'posts_per_page' => 3,
'cat' => 317,
'orderby' => 'DESC'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="blog_post_sekcja">
<a href="<?php echo get_permalink($post->ID); ?>">
<p class="news_title"><?php $title = get_the_title(); echo wp_trim_words( $title , '4', $more = null ); ?></p></a>
<?php if($first_post) { ?>
<div class="post_skrot"><?php echo wp_trim_words( get_the_content(), $num_words = 30, $more = '... <a class="button_more" href="'. get_permalink($post->ID) . '">pokaż więcej » </a>' ); ?></div>
<?php } else { ?>
<div class="post_skrot"><a class="button_more" href="<?php echo get_permalink($post->ID); ?>">pokaż więcej » </a></div>
<?php } ?>
</div>
<?php
//Change value of $first_post
$first_post = false;
endwhile;
wp_reset_query(); ?>
</ul>
<div class="blog_more">
Więcej wpisów</div>
</div>
</div>
</div>
I've got: Parse error: syntax error, unexpected end of file...on line 145. 145 is my last line in code and on this line I have only <?php get_footer(); ?>
I think it must be something with endwhile; or another syntax.
Your $args array is off a little bit. Should be:
<div id="sliders-2-3">
<div class="elementy-oferty">
<div class="slider-4">
<div class="border-video">
<div class="content-slider-4">
<div class="blog_top_title">Blog</div>
<ul>
<?php
//Establish first post check variable
$first_post = true;
$args = array(
'posts_per_page' => 3,
'cat' => 317,
'orderby' => 'date',
'order' => 'DESC' // or 'ASC like in your original code.'
);
$the_query = new WP_Query( $args );
if ( have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
<div class="blog_post_sekcja">
<a href="<?php echo get_permalink($post->ID); ?>">
<p class="news_title"><?php $title = get_the_title(); echo wp_trim_words( $title , '4', $more = null ); ?></p></a>
<?php if ( $first_post ) : ?>
<div class="post_skrot"><?php echo wp_trim_words( get_the_content(), $num_words = 30, $more = '... <a class="button_more" href="'. get_permalink($post->ID) . '">pokaż więcej » </a>' ); ?></div>
<?php else : ?>
<div class="post_skrot"><a class="button_more" href="<?php echo get_permalink($post->ID); ?>">pokaż więcej » </a></div>
<?php endif; ?>
</div>
<?php
$first_post = false;
}
}
wp_reset_postdata();
?>
</ul>
<div class="blog_more">
Więcej wpisów</div>
</div>
</div>
</div>

Categories