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>
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I'm trying to add pagination to my [shortcut]. This is my code:
<?php }
//LatestCar Function
function carforyou_LatestCar($atts){
ob_start();?>
<div class="row">
<?php
extract( shortcode_atts(array('show' =>''), $atts ));
extract( shortcode_atts(array('brand' =>''), $atts ));
$loop = new WP_Query( array(
'post_type' => 'auto',
'auto-brand' => $brand,
'posts_per_page'=>$show,
'offset' => 0
));// $count = $loop->found_posts; echo $count;
while ($loop->have_posts()) : $loop->the_post();
global $post; ?>
<div class="col-list-3">
<div class="featured-car-list">
<div class="featured-car-img">
<a alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>" href="<?php the_permalink();?>">
<?php if(has_post_thumbnail()):
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif;
?>
</a>
<?php carforyou_AutoType(); ?>
<div class="compare_item">
<div class="checkbox">
<button id="compare_auto_btn" onclick="<?php echo esc_js('javascript:productCompare('.$post->ID.')'); ?>"><?php esc_html_e('Compare','carforyou'); ?></button>
</div>
</div>
</div>
<div class="featured-car-content">
<h6><a title="<?php echo get_the_title(); ?>" href="<?php the_permalink(); ?>"><?php $title = get_the_title(); echo mb_strimwidth($title, 0, 30, '...'); ?></a></h6>
<div class="price_info">
<?php if(!empty($post->DREAM_auto_price)): ?>
<p class="featured-price"><?php carforyou_curcy_prefix(); ?><?php echo number_format_i18n(esc_html($post->DREAM_auto_price)); ?></p>
<?php endif; ?>
<div class="car-location">
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?>
<span><i class="fa fa-map-marker" aria-hidden="true"></i> <?php echo esc_html($location); ?> </span>
<?php endif; ?>
</div>
</div>
<ul>
<?php carforyou_featuredList(); ?>
</ul>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
<?php }
Above code using [latestcars show="10" brand="ford"] displays 10 cars made by ford. I want to add pagination, so I have added folllwing modification:
<?php }
//LatestCar Function
function carforyou_LatestCar($atts){
ob_start();?>
<div class="row">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
extract( shortcode_atts(array('show' =>''), $atts ));
extract( shortcode_atts(array('brand' =>''), $atts ));
$loop = new WP_Query( array(
'post_type' => 'auto',
'auto-brand' => $brand,
'paged' =>$paged,
'posts_per_page'=>$show,
'offset' => 0
));
// $count = $loop->found_posts; echo $count;
while ($loop->have_posts()) : $loop->the_post();
global $paged, $post;
?>
<div class="col-list-3">
<div class="featured-car-list">
<div class="featured-car-img">
<a alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>" href="<?php the_permalink();?>">
<?php if(has_post_thumbnail()):
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif;
?>
</a>
<?php carforyou_AutoType(); ?>
<div class="compare_item">
<div class="checkbox">
<button id="compare_auto_btn" onclick="<?php echo esc_js('javascript:productCompare('.$post->ID.')'); ?>"><?php esc_html_e('Compare','carforyou'); ?></button>
</div>
</div>
</div>
<div class="featured-car-content">
<h6><a title="<?php echo get_the_title(); ?>" href="<?php the_permalink(); ?>"><?php $title = get_the_title(); echo mb_strimwidth($title, 0, 30, '...'); ?></a></h6>
<div class="price_info">
<?php if(!empty($post->DREAM_auto_price)): ?>
<p class="featured-price"><?php carforyou_curcy_prefix(); ?><?php echo number_format_i18n(esc_html($post->DREAM_auto_price)); ?></p>
<?php endif; ?>
<div class="car-location">
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?>
<span><i class="fa fa-map-marker" aria-hidden="true"></i> <?php echo esc_html($location); ?> </span>
<?php endif; ?>
</div>
</div>
<ul>
<?php carforyou_featuredList(); ?>
</ul>
</div>
</div>
</div>
<?php endwhile;
carforyou_pagination();
else:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
extract( shortcode_atts(array('show' =>''), $atts ));
extract( shortcode_atts(array('brand' =>''), $atts ));
$loop = new WP_Query( array(
'post_type' => 'auto',
'auto-brand' => $brand,
'paged' =>$paged,
'posts_per_page'=>$show,
'offset' => 0
));
while ($loop->have_posts()) : $loop->the_post();
?>
<div class="col-list-3">
<div class="featured-car-list">
<div class="featured-car-img">
<a alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>" href="<?php the_permalink();?>">
<?php if(has_post_thumbnail()):
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif;
?>
</a>
<?php carforyou_AutoType(); ?>
<div class="compare_item">
<div class="checkbox">
<button id="compare_auto_btn" onclick="<?php echo esc_js('javascript:productCompare('.$post->ID.')'); ?>"><?php esc_html_e('Compare','carforyou'); ?></button>
</div>
</div>
</div>
<div class="featured-car-content">
<h6><a title="<?php echo get_the_title(); ?>" href="<?php the_permalink(); ?>"><?php $title = get_the_title(); echo mb_strimwidth($title, 0, 30, '...'); ?></a></h6>
<div class="price_info">
<?php if(!empty($post->DREAM_auto_price)): ?>
<p class="featured-price"><?php carforyou_curcy_prefix(); ?><?php echo number_format_i18n(esc_html($post->DREAM_auto_price)); ?></p>
<?php endif; ?>
<div class="car-location">
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?>
<span><i class="fa fa-map-marker" aria-hidden="true"></i> <?php echo esc_html($location); ?> </span>
<?php endif; ?>
</div>
</div>
<ul>
<?php carforyou_featuredList(); ?>
</ul>
</div>
</div>
</div>
<?php endwhile;
carforyou_pagination();
endif;
}
?>
Above solution returns following error code which I can't trace:
PHP Parse error: syntax error, unexpected
'else' (T_ELSE) in
/var/www/clients/clientxxx/webxxx/web/wp-content/themes/xxxxxx/functions/basic-functions.php
on line 439
Line 439 is "else:"
<?php endwhile;
carforyou_pagination();
else:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
(...)
Any advice? Thanks
Strip out the HTML tags and it becomes pretty clear that your if...else control structure is not correct. The else in question has no corresponding if structure before it.
while ($loop->have_posts()) : $loop->the_post();
global $paged, $post;?>
<?php if(has_post_thumbnail()): //OPEN IF ONE
the_post_thumbnail('carforyou_small', array('class' => 'img-responsive'));
else:
echo "<div class='is-empty-img-box'></div>";
endif; //CLOSE IF ONE
?>
<?php carforyou_AutoType(); ?>
<?php if(!empty($post->DREAM_auto_price)): ?> //OPEN IF TWO
<?php endif; ?> //CLOSE IF TWO
<?php $term_list = wp_get_post_terms($post->ID, 'auto-location', array("fields" => "all"));
foreach($term_list as $term_single)
$location = $term_single->name;
?>
<?php if(!empty($location)): ?> //OPEN IF THREE
<?php endif; ?> //CLOSE IF THREE
<?php carforyou_featuredList(); ?>
<?php endwhile;
carforyou_pagination();
else: //SO WHERE IS IF FOUR???
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
extract( shortcode_atts(array('show' =>''), $atts ));
...
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();
?>
I created a custom post type called "library", with its "documentation" taxonomy; The problem occurs in the pagination of the taxonomy template (taxonomy-documentation.php).
I have determined a number of "18" posts per page, for the number of posts there should be "7" pages, but I list "16" pages, the pages from "8" to "16" are empty.
The url of archive for the taxonomy is: Documentation Archive
The template loop is as follows:
<?php
$term = $wp_query->queried_object;
$getterm = $term->slug; // get current slug (E.g. winter2015)
$args = (array(
'post_type' => 'library',
'showposts' => 18,
'paged'=>$paged,
'tax_query' => array(
array(
'taxonomy' => 'documentation',
'field' => 'slug',
'terms' => $getterm
),
),
) );
$query = new wp_query( $args );
if ( $query -> have_posts() ) : while ( $query -> have_posts() ) : $query -> the_post(); ?>
<?php setPostViews(get_the_ID()); ?>
<div class="col-md-2">
<?php if ( get_post_meta( get_the_ID(), 'download_image', true ) ) : ?>
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php get_the_title(); ?>">
<?php
$postID = $post->ID;
$imageURI = get_post_meta($postID, 'download_image', true);
$attachmentID = pn_get_attachment_id_from_url ($imageURI);
$imagearray = wp_get_attachment_image_src( $attachmentID, 'full');
$imageURI = $imagearray[0];
$thumbarray = wp_get_attachment_image_src( $attachmentID, 'library-thumbnail');
$thumb_imageURI = $thumbarray[0];
echo "<img class='document-thumbnail' src='". $thumb_imageURI . "' alt='". get_the_title() ."' />";
?>
</a>
<?php endif; ?>
<a class="document-title" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo mb_strimwidth(get_the_title(), 0, 40, '...'); ?></a><br />
<span><?php echo __('Published by', 'cyberdocentes'); ?> <a class="author-link" href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><?php the_author(); ?></a></span>
</div>
<?php endwhile; rewind_posts(); ?>
<div class="clear"></div>
<div id="pagination">
<?php include(TEMPLATEPATH . '/pagenavi.php'); if (function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
<div class="navigation">
<div class="alignleft">
<?php next_posts_link(__('Next posts','cyberdocentes')); ?>
</div>
<div class="alignright">
<?php previous_posts_link(__('Previous posts','cyberdocentes')); ?>
</div>
</div>
<?php } ?>
</div>
<div class="clear"></div>
<?php else : ?>
<?php endif; ?>
<?php flush(); ?>
Solved code:
<div class="documents-list">
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'documentation' ) );
global $wp_query;
query_posts( array_merge( $wp_query->query, array( 'posts_per_page' => 18 ) ) );
if (have_posts()) : while ( have_posts() ) : the_post(); ?>
//CODE OF THE ARTICLES HERE
<?php endwhile; rewind_posts(); ?>
<?php endif; ?>
<div class="clear"></div>
<div id="pagination">
<?php include(TEMPLATEPATH . '/pagenavi.php'); if (function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
<div class="navigation">
<div class="alignleft">
<?php next_posts_link(__('Next posts','cyberdocentes')); ?>
</div>
<div class="alignright">
<?php previous_posts_link(__('Previous posts','cyberdocentes')); ?>
</div>
</div>
<?php } ?>
</div>
<div class="clear"></div>
<?php flush(); ?>
</div>
<?php
$args=array(
'post_type'=>'post',
'cat' => '',
'posts_per_page' => 4,
'paged'=>$paged
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div id="box1">
<h1 class="blog1"><?php the_title(); ?></h1>
<h2 class="blog2">Posted By :- <?php the_author_meta('display_name'); ?> <span class="blog3">
<?php echo get_the_date(); ?></span></h2>
<?php $a=wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<span class="blog4"><img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo $a; ?>&w=200&h=150&q=100" alt=""></span>
<p class="blogcontent"><?php $a=get_the_content();
$b=strlen($a);
if($b>770)
{
$con = substr($a, 0, strrpos(substr($a,0,770),' ')). '....';
echo $con;
?>
<p style=" float:right;"><a style ="margin-top:15px;" href="<?php echo get_permalink($post->ID);?> ">Read More</a></p>
<?php
}
else
{
echo $a;
}
?>
</p>
</div>
<?php //endforeach;
endwhile; ?>
<?php endif; ?>
<span style="padding:30px;"><?php if(function_exists('wp_paginate')) {wp_paginate();}
$wp_query = null;
$wp_query = $temp;
wp_reset_query(); ?>
</span>
I working on wordpress blog and make a pagination in blog there were issue in pagination.when click on page 2 the url change but page not changed.i am using the following code for that
Thanks & Regards
Try this code:
<?php
$args=array(
'post_type'=>'post',
'cat' => '',
'posts_per_page' => 4,
'paged'=>$paged
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div id="box1">
<h1 class="blog1"><?php the_title(); ?></h1>
<h2 class="blog2">Posted By :- <?php the_author_meta('display_name'); ?> <span class="blog3">
<?php echo get_the_date(); ?></span></h2>
<?php $a=wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<span class="blog4"><img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo $a; ?>&w=200&h=150&q=100" alt=""></span>
<p class="blogcontent"><?php $a=get_the_content();
$b=strlen($a);
if($b>770)
{
$con = substr($a, 0, strrpos(substr($a,0,770),' ')). '....';
echo $con;
?>
<p style=" float:right;"><a style ="margin-top:15px;" href="<?php echo get_permalink($post->ID);?> ">Read More</a></p>
<?php
}
else
{
echo $a;
}
?>
</p>
</div>
<?php //endforeach;
endwhile; ?>
<?php endif; ?>
<span style="padding:30px;">
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
$wp_query = null;
$wp_query = $temp;
wp_reset_query(); ?>
</span>
Alternatively, you can see this tutorial if you want to have numbered pagunation.
I'm about to finish a wordpress-site with a custom theme and several custom-post-types. Now i wanted to change the permalink settings to %post-name%, to make the url's nicer and this is where the problems start.
I have 3 custom-post-types next to the default post-format: events, galleries, shop. Now when I load the page "events (using the template-events.php, what does a wp_query to get all the events), I get all posts. It basically ignores the defined template and loads the one defined for the posts-page, same happens for the shop-page.
The strange thing is that the gallery page (loading the same kind of template file to do the wp_query) works fine.
When I change back to the default permalink-setting everything works fine...
Thanks for any hint!
here my template-events.php
<?php
/*
Template Name: Events
*/
?>
<?php get_header(); ?>
<?php
//Fix homepage pagination
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
$now = strtotime("now");
$args = array(
'post_type' => 'events',
'posts_per_page' => 40,
'post_status' => 'publish',
'meta_key' => '_cmb_date_timestamp',
'orderby' => 'meta_value',
'order' => 'ASC',
'paged' => $paged,
'meta_query' => array(
array(
'key' => '_cmb_date_timestamp',
'value' => $now,
'type' => 'NUMERIC',
'compare' => '>=' )
)
);
// Create a new filtering function that will add our where clause to the query
function filter_where( $where = '' ) {
// posts in the last 30 days
$where .= " AND _cmb_date_timestamp < '" . date('Y-m-d') . "'";
return $where;
}
//add_filter( 'posts_where', 'filter_where' );
$events_query = new WP_Query($args);
if( $events_query->have_posts() ) :
$derLudwig = get_theme_mod( 'eventsHeading', '');
$url = esc_url( get_theme_mod( 'events_image' ) );
echo '<div class="overview-header" style="background-image: url('.$url.');"></div>';
echo '<h2 class="overview">der Ludwig '.$derLudwig.'</h2>';
?>
<div id="filters">
<div id="filterButtons">
<a id="filterOpen" class="filterB" href="#"><img src="<?php echo get_bloginfo("template_url"); ?>/images/sub-navi2.png"/></a>
<a id="filterClose" class="filterB" href="#"><img src="<?php echo get_bloginfo("template_url"); ?>/images/filter-close.png"/></a>
</div>
<?php
/* FILTERS */
$args = array(
'type' => 'events',
'taxonomy' => 'event_category',
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
echo '<div id="categories">';
echo '<h5>Kategorien: </h5>';
echo '<ul>';
foreach ($categories as $category) {
echo '<li>' . $category->name . '</li>';
}
echo '</ul>';
echo '</div>';
?>
Clear
</div>
<!--BEGIN #content -->
<div id="content" class="clearfix">
<?php
echo '<img class="loader" src="'.get_bloginfo('template_url').'/images/loader.gif"/>';
echo '<div id="primary" class="hfeed event-overview">';
while( $events_query->have_posts() ) : $events_query->the_post();
// infos
$time = get_post_meta($post->ID, '_cmb_time', true);
$cdateStamp = get_post_meta($post->ID, '_cmb_date_timestamp');
$monthName = date_i18n('F', $cdateStamp[0]);
$weekdayNumber = date_i18n('j', $cdateStamp[0]);
$weekday = date_i18n('D', $cdateStamp[0]);
$locations = get_the_terms( $post->ID, 'locations' );
$tickets = get_post_meta($post->ID, '_ludwig_events_tickets', true);
$featured = get_post_meta($post->ID, '_ludwig_events_display_featured', true);
$reservation = get_post_meta($post->ID, '_ludwig_events_display_reservation', true);
// grab everything else
$custom_bg = get_post_meta($post->ID, '_zilla_portfolio_display_background', true);
$portfolio_caption = get_post_meta($post->ID, '_zilla_portfolio_caption', true);
?>
<?php
if(!isset($currentMonth) || $currentMonth != $monthName){
?>
<h2 class="<?php echo lcfirst($monthName); ?>"><?php echo $monthName; ?></h2>
<?php
}
$currentMonth = $monthName;
?>
<!--BEGIN .hentry-->
<div id="post-<?php the_ID(); ?>" class="event-small <?php echo lcfirst($monthName); ?>">
<!--BEGIN .entry-content -->
<div class="entry-content">
<div class="eTop">
<span class="dateDay"><?echo $weekdayNumber; ?></span>
<span class="dateMonth"><? _e($monthName, 'ludwig-events'); ?></span>
<span class="dateWeekDay"><? _e($weekday, 'ludwig-events'); ?></span>
</div>
<?php the_post_thumbnail('event-small'); ?>
<div class="eBottom">
<?php the_title('<h3>', '</h3>'); ?>
<span class="eventWo">
<?php
if ( $locations && !is_wp_error( $locations ) ) {
foreach ( $locations as $location ) {
echo $location->name;
}
}
?>
, <?php echo $time; ?>Uhr</span>
<div class="event-buttons">
<div class="inner">
<div class="centerContainer">
<h4>Tickets</h4>
<?php ticketsLink($tickets); ?>
<?php reservationLink($reservation); ?>
</div>
</div>
</div>
</div>
<!--END .entry-content -->
</div>
</div>
<?php endwhile; ?>
<!--END #primary .hfeed-->
</div>
<?php else: ?>
<div id="content" class="nocontent">
<!--BEGIN #post-0-->
<div id="post-0" <?php post_class(); ?>>
<h2 class="entry-title"><?php _e('Keine Events gefunden', 'ludwig') ?></h2>
<!--BEGIN .entry-content-->
<div class="entry-content">
<p><?php _e("Hoppala, das sollte eigentlich nicht passieren", "ludwig") ?></p>
<!--END .entry-content-->
</div>
<!--END #post-0-->
</div>
</div>
<?php endif; ?>
<?php remove_filter( 'posts_where', 'filter_where' ); ?>
<?php get_footer(); ?>
here the working template-gallery.php
<?php
/*
Template Name: Fotos
*/
?>
<?php get_header(); ?>
<?php
//Fix homepage pagination
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
// CHECK THAT THIS ONE ISTN DOWN
/*
$args = array(
'post_type' => 'gallery',
'posts_per_page' => 1,
'post_status' => 'publish',
'orderby' => 'modified',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'gallery_category',
'field' => 'id',
'terms' => array( $term_id ),
'operator' => 'IN'
)
),
'paged' => $paged
);
$sina_query = new WP_Query($args);
$sinaString = '';
if( $posts_query->have_posts() ) :
while( $posts_query->have_posts() ) : $posts_query->the_post();
?>
<?php endwhile; ?>
<?php endif; ?>
*/
$args = array(
'post_type' => 'gallery',
'orderby' => 'modified',
'order' => 'DESC',
'posts_per_page' => 10,
'paged' => $paged
);
$posts_query = new WP_Query($args);
if( $posts_query->have_posts() ) :
$derLudwig = get_theme_mod( 'fotosHeading', '');
$url = esc_url( get_theme_mod( 'fotos_image' ) );
echo '<div class="overview-header" style="background-image: url('.$url.');"></div>';
echo '<h2 class="overview">der Ludwig '.$derLudwig.'</h2>';
?>
<div id="filters">
<div id="filterButtons">
<a id="filterOpen" class="filterB" href="#"><img src="<?php echo get_bloginfo("template_url"); ?>/images/sub-navi2.png"/></a>
<a id="filterClose" class="filterB" href="#"><img src="<?php echo get_bloginfo("template_url"); ?>/images/filter-close.png"/></a>
</div>
<?php
/* FILTERS */
$args = array(
'type' => 'events',
'taxonomy' => 'gallery_category',
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
echo '<div id="categories">';
echo '<h5>Kategorien: </h5>';
echo '<ul>';
foreach ($categories as $category) {
echo '<li>' . $category->name . '</li>';
}
echo '</ul>';
echo '</div>';
?>
Clear
</div>
<!--BEGIN #content -->
<div id="content" class="clearfix">
<?php
echo '<img class="loader" src="'.get_bloginfo('template_url').'/images/loader.gif"/>';
echo '<div id="primary" class="hfeed gallery-overview">';
$counter = 0;
while( $posts_query->have_posts() ) : $posts_query->the_post();
$fotograf = get_post_meta($post->ID, '_ludwig_gallery_fotograf', true);
?>
<?php
if ($counter == 1) {
?>
<div id="post-<?php the_ID(); ?>" class="gallery-grid post-<?php echo $counter++; ?>">
<!--BEGIN .entry-content -->
<div class="entry-content">
<a href="<?php echo get_permalink(); ?>">
<div class="overlayContainer">
<div class="overlay">
<div class="content">
<div class="inner">
<?php
/*
$terms = get_the_terms( $post->ID, 'gallery_category');
if ( $terms && ! is_wp_error( $terms ) ) :
$draught_links = array();
foreach ( $terms as $term ) {
$draught_links[] = $term->name;
}
$on_draught = join( ", ", $draught_links );
*/
?>
<p class="galleryCategories">
<span><?php //echo $on_draught; ?></span>
</p>
<?php //endif; ?>
<h3><?php the_title(); ?></h3>
<p class="fotograf">von<br><span><?php echo $fotograf; ?></span></p>
</div>
</div>
</div>
</div>
<?php the_post_thumbnail('gallery-mid'); ?></a>
</div>
</div>
<?php echo $counter++; ?>
<?php
} else {
?>
<div id="post-<?php the_ID(); ?>" class="gallery-grid post-<?php echo $counter++; ?>">
<!--BEGIN .entry-content -->
<div class="entry-content">
<a href="<?php echo get_permalink(); ?>">
<div class="overlayContainer">
<div class="overlay">
<div class="content">
<div class="inner">
<?php
/*
$terms = get_the_terms( $post->ID, 'gallery_category');
if ( $terms && ! is_wp_error( $terms ) ) :
$draught_links = array();
foreach ( $terms as $term ) {
$draught_links[] = $term->name;
}
$on_draught = join( ", ", $draught_links );
*/
?>
<p class="galleryCategories">
<span><?php //echo $on_draught; ?></span>
</p>
<?php //endif; ?>
<h3><?php the_title(); ?></h3>
<p class="fotograf">von<br><span><?php echo $fotograf; ?></span></p>
</div>
</div>
</div>
</div>
<?php the_post_thumbnail('gallery-mid'); ?></a>
</div>
</div>
<?php } ?>
<?php endwhile; ?>
<!--END .hfeed -->
</div>
<a class="archivlink" href="#">⌸ Archiv</a>
<div class="navigation">
<div class="next-posts"><?php next_posts_link('« Older Entries', $posts_query->max_num_pages) ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries »', $posts_query->max_num_pages) ?></div>
</div>
<?php else: ?>
<div id="content" class="nocontent">
<!--BEGIN #post-0-->
<div id="post-0" <?php post_class(); ?>>
<h2 class="entry-title"><?php _e('Keine Fotos gefunden', 'ludwig') ?></h2>
<!--BEGIN .entry-content-->
<div class="entry-content">
<p><?php _e("Hoppala, das sollte eigentlich nicht passieren", "ludwig") ?></p>
<!--END .entry-content-->
</div>
<!--END #post-0-->
</div>
</div>
<?php endif; ?>
<?php get_footer(); ?>
Hint from me (Since you do not put a code):
Nothing wrong with the permalink. It should be work. I believe what cause this is your code. Please, double check your code and re-install your WordPress, and try again.