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>
Related
I would like to Edit the Grid Artist page to only have 12 artists and land on the producers section instead of all artist.
Here' s the link of website page : http://cascaderecords.fr/roster/
PHP code:
<?php
if (ci_setting('artists_isotope') == 'enabled' AND !wp_is_mobile() AND !is_tax() ):
?>
<ul class="filters-nav group">
<li><?php _e('All Artists', 'ci_theme'); ?></li>
<?php
$args = array('hide_empty' => 1);
$cats = get_terms('artist-category', $args);
?>
<?php foreach ( $cats as $cat ): ?>
<li><?php echo $cat->name; ?></li>
<?php endforeach; ?>
</ul>
<?php
endif; // is isotope enabled
global $paged;
if ( ci_setting('artists_isotope') == 'enabled' AND !wp_is_mobile() AND !is_tax() ) {
$args = array(
'post_type' => 'cpt_artists',
'posts_per_page' => -1
);
} else {
$args = array(
'post_type' => 'cpt_artists',
'posts_per_page' => ci_setting('artists_per_page'),
'paged' => $paged
);
}
$the_query = !empty($the_query) ? $the_query : new WP_Query($args);
?>
<article class="row">
<ul class="col-md-12 items-list-grid filter-container <?php echo $filter; ?>">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $cats = wp_get_object_terms($post->ID, 'artist-category'); ?>
<li class="<?php foreach ( $cats as $cat ) : echo $cat->slug.' '; endforeach; echo $grid; ?>">
<article id="artist-<?php the_ID(); ?>" <?php post_class('row'); ?>>
<div class="col-md-12">
<?php if ( has_post_thumbnail() ) : ?>
<figure>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('ci_thumb_square'); ?>
</a>
</figure>
<?php endif; ?>
<h2><?php the_title(); ?></h2>
</div><!-- /col-md-12 -->
</article><!-- /row -->
</li><!-- /col-md-4 -->
<?php endwhile; wp_reset_postdata(); ?>
</ul>
Try change:
'posts_per_page' => -1
to:
'posts_per_page' => 12
Not sure what "ci_setting('artists_per_page')" is in below variable, need more info:
'posts_per_page' => ci_setting('artists_per_page'),
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>
I Guys! I'm working on a pagination for this theme homepage. The original code is:
<?php
/**
Blog
**/
$display_count = get_theme_mod('wpex_home_blog_count', '30');
$wpex_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => $display_count,
'no_found_rows' => true,
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<?php
// Display post meta details
wpex_post_meta() ;?>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
What I did is, I changed it to
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=4' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<ul class="post-meta clr">
<li class="meta-date">
<?php _e('Posted on','wpex'); ?>
<span class="meta-date-text"><?php echo get_the_date(); ?></span>
</li>
</ul>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endwhile; ?>
</div>
<?php wp_pagenavi();?>
<?php wp_reset_postdata(); ?>
</article>
This seems to work on the first page, but when i go to page 2, it gives an copy after copy after copy of the whole page, like an infinate page one. That's not how it should work.
Any ideas what goes wrong here? Does this make any sense to you?
EDIT:
I tried the following. Right now the first page looks good, but when i press the second page on the pagination, it outputs the same as the first.
<?php
$args = array(
'paged' => (get_query_var('paged') ? get_query_var('paged') : 1),
'posts_per_page' => 4
);
query_posts($args);
?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<ul class="post-meta clr">
<li class="meta-date"><?php _e('Posted on','wpex'); ?> <span class="meta-date-text"><?php echo get_the_date(); ?></span> </li>
</ul>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endwhile; ?>
<?php wp_pagenavi();?>
</div><!-- #homepage-portfolio -->
<?php endif; ?>
<?php wp_reset_query(); ?>
</article><!-- #post -->
<?php endwhile; ?>
Whole original code:
<div id="primary" class="content-area clr">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article class="homepage-wrap clr">
<?php
/**
Post Content
**/ ?>
<?php if ( get_the_content() !== '' ) { ?>
<div id="homepage-content" class="entry clr">
<?php the_content(); ?>
</div><!-- .entry-content -->
<?php } ?>
<?php
/**
Features
**/
$wpex_query = new WP_Query(
array(
'order' => 'ASC',
'orderby' => 'menu_order',
'post_type' => 'features',
'posts_per_page' => '-1',
'no_found_rows' => true,
)
);
if ( $wpex_query->posts ) { ?>
<div id="homepage-features" class="clr">
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<?php get_template_part( 'content-features', get_post_format() ); ?>
<?php if ( $wpex_count == '4' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-features -->
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php
/**
Portfolio
**/
$display_count = get_theme_mod('wpex_home_portfolio_count', '8');
$wpex_query = new WP_Query(
array(
'post_type' => 'portfolio',
'posts_per_page' => $display_count,
'no_found_rows' => true,
'tax_query' => wpex_home_portfolio_taxonomy(),
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-portfolio" class="clr">
<h2 class="heading"><span><?php _e( 'Recent Work', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<?php get_template_part( 'content-portfolio', get_post_format() ); ?>
<?php if ( $wpex_count == '4' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php
/**
Blog
**/
$display_count = get_theme_mod('wpex_home_blog_count', '30');
$wpex_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => $display_count,
'no_found_rows' => true,
)
);
if ( $wpex_query->posts && '0' != $display_count ) { ?>
<div id="homepage-blog" class="clr">
<h2 class="heading"><span><?php _e( 'From The Blog', 'wpex' ); ?></span></h2>
<?php $wpex_count=0; ?>
<?php foreach( $wpex_query->posts as $post ) : setup_postdata( $post ); ?>
<?php $wpex_count++; ?>
<article class="recent-blog-entry clr col span_1_of_3 col-<?php echo $wpex_count; ?>">
<?php
// Display post thumbnail
if ( has_post_thumbnail() ) { ?>
<div class="recent-blog-entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>">
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>" />
</a>
</div><!-- .recent-blog-entry-thumbnail -->
<?php } ?>
<header>
<h3 class="recent-blog-entry-title"><?php the_title(); ?></h3>
<?php
// Display post meta details
wpex_post_meta() ;?>
</header>
<div class="recent-blog-entry-content entry clr">
<?php wpex_excerpt( 18, false ); ?>
</div><!-- .recent-blog-entry-content -->
</article><!-- .recent-blog -->
<?php if ( $wpex_count == '3' ) { ?>
<?php $wpex_count=0; ?>
<?php } ?>
<?php endforeach; ?>
</div><!-- #homepage-portfolio -->
<?php } ?>
<?php wp_reset_postdata(); ?>
</article><!-- #post -->
<?php comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
Try declaring $paged outside, and call this in the query_posts
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 4
);
query_posts($args . '&paged=' . $paged);
I might have found an answer for this myself, apparently it's different when you use pagination on the frontpage. I used this and it seems to be working!:
if( is_front_page() ){
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
} else {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
}
I need to use the same page for different taxonomies and terms.
How can I retrieve the taxonomies and the terms from the URL and run the same page for those I that I want?
The query should be run through a URL since I am not using forms.
When the user clicks on the link, a new page should be opened that is an archive of posts having custom post type, taxonomy and taxonomy terms specified in the URL.
This is the code that I have right now:
<? /*
* Template Name: Activities template
* Description: Template for activties like restaurants, pubs, etc.
*/
?>
<?php $options = get_option('mh_options'); ?>
<?php get_header(); ?>
<?php
if ( get_query_var('paged') ) {$paged = get_query_var('paged');}
if ( get_query_var('page') ) {$paged = get_query_var('page');}
$args = array(
'post_type' => 'activties',
'tax_query' => array(
array(
'taxonomy' => 'restaurants',
'field' => 'slug',
'terms' => 'italian'
),
'paged' => $paged
)
);
query_posts( $args ); ?>
<div class="wrapper clearfix">
<div class="main">
<div class="content <?php mh_content_class(); ?>">
<?php mh_before_page_content(); ?>
<?php dynamic_sidebar('pages-1'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!-- <?php the_content(); ?> -->
<article <?php post_class(); ?>>
<div class="loop-wrap loop-layout2">
<div class="clearfix">
<div class="loop-thumb">
<a href="<?php the_permalink(); ?>">
<?php if( get_field('business_logo') ): ?>
<?php $image = wp_get_attachment_image_src(get_field('business_logo'), 'loop'); ?>
<img src="<?php echo $image[0]; ?>" alt="<?php the_field('business_logo');?>" data-thumb="<?php echo $thumb[0]; ?>" />
<?php else: echo '<img src="' . get_template_directory_uri() . '/images/noimage_300x225.png' . '" alt="No Picture" />'; ?>
<?php endif; ?>
</a>
</div>
<div class="loop-content">
<header>
<h3 class="loop-title"><?php the_title(); ?></h3>
</header>
<?php if (get_field('business_description')): ?>
<?php $text_to_trim = get_field('business_description');
echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?>
<?php endif; ?>
<?php if (get_field('business_paying_desc')): ?>
<?php $text_to_trim = get_field('business_paying_desc');
echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?>
<?php endif; ?>
</div>
</div>
</div>
</article>
<?php dynamic_sidebar('pages-2'); ?>
<?php endwhile; ?>
<!-- <?php wp_reset_postdata(); ?> -->
<?php wp_reset_query(); ?>
<?php if (isset($options['comments_pages']) ? $options['comments_pages'] : false) : ?>
<section>
<?php comments_template(); ?>
</section>
<?php endif; ?>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php mh_second_sb(); ?>
</div>
<?php get_footer(); ?>
EDIT
After a few days, I found the solution that I am going to post, however it has got an issue: I cannot see the list of the posts if a post has got multiple terms (more than 1 term basically) selected by the checkboxes when it is created or edited.
This is my taxonomy.php file
<?php
$post = $wp_query->post;
/*$catMerc = array('restaurants','pubs', 'the-pizzerias', 'bars', 'cafes', 'nightlife-clubs', 'shopping', 'the-coffeeshops');*/
$catMerc = array('the-restaurants', 'the-coffeeshops', 'the-pizzerias', 'shopping', 'nightlife-clubs', 'cafes', 'bars', 'pubs');
$termsObjects = wp_get_object_terms($post->ID, $catMerc);
//Assuming your post only has one category, if theres more it will return multiple objects in it's return array:
$currentCustomCat = $termsObjects[0]->slug;
$currentCatMerc = get_query_var('taxonomy');
//you can have 'name' instead of 'slug' if that helps too
$customcatarray = array('american-pubs-exclusive5', 'american-pubs-in-town', 'beer-houses-exclusive5', 'beer-houses-in-town', 'free-joints-exclusive5', 'free-joints-in-town', 'local-atmosphere-exclusive5', 'local-atmosphere-in-town', 'spanish-atmosphere-exclusive5', 'spanish-atmosphere-in-town', 'take-away-exclusive5', 'take-away-in-town', 'traditional-dutch-exclusive5', 'traditional-dutch-in-town', 'african-exclusive-5', 'african-in-town', 'argentinian-restaurants-exclusive5', 'argentinian-restaurants-in-town',' asian-restaurants-exclusive5', 'asian-restaurants-in-town', 'dutch-restaurants-exclusive5', 'dutch-restaurants-in-town', 'french-restaurants-exclusive5', 'french-restaurants-in-town', 'italian-restaurants-exclusive5', 'italian-restaurants-in-town', 'seafood-restaurants-exclusive5', 'seafood-restaurants-in-town', 'spanish-restaurants-exclusive5', 'spanish-restaurants-in-town', 'cocktail-bars-exclusive5', 'cocktail-bars-in-town', 'disco-bars-exclusive5', 'disco-bars-in-town', 'dutch-bars-exclusive5', 'dutch-bars-in-town', 'internet-cafes-exclusive5', 'internet-cafes-in-town', 'lounge-bars-exclusive5', 'lounge-bars-in-town', 'art-cafes-exclusive5', 'art-cafes-in-town', 'breakfast-lunch-exclusive5','breakfast-lunch-in-town', 'famous-cafes-exclusive5', 'famous-cafes-in-town', 'fashion-cafes-exclusive5', 'fashion-cafes-in-town', 'timeout-exclusive5', 'timeout-in-town', 'best-boutiques-exclusive5','best-boutiques-in-town', 'famous-brands-exclusive5', 'famous-brands-in-town', 'sportswear-exclusive5', 'sportswear-in-town', 'the-pizzerias-with-table-service-in-town', 'the-pizzerias-with-table-service-exclusive5', 'the-pizzerias-takeway-in-town', 'the-pizzerias-takeaway-exclusive5', 'the-coffeeshops-in-town', 'the-coffeeshops-exclusive5');
if (in_array($currentCatMerc, $catMerc) && in_array($currentCustomCat, $customcatarray) ) {include(TEMPLATEPATH.'/page_activities.php'); }
/*if( $currentCustomCat == "italian" || $currentCustomCat == "local-atmosphere"){
//It matched, do stuff here
{include(TEMPLATEPATH.'/single_activities.php'); }
}*/
else { /*include(TEMPLATEPATH.'/page.php'); */
$pagelink=get_page_link (get_page_by_title( 'Homepage' ));
header("Location: $pagelink",TRUE,301);
}
?>
And this is my page_activities.php file
<?php
if ( get_query_var('paged') ) {$paged = get_query_var('paged');}
if ( get_query_var('page') ) {$paged = get_query_var('page');}
$args = array(
'post_type' => 'activities',
'tax_query' => array(
array(
'taxonomy' => $currentCatMerc,
'field' => 'slug',
'terms' => $currentCustomCat
),
'paged' => $paged,
'posts_per_page'=>'10',
)
);
$args2 = array(
'post_type' => 'activities',
'paged' => $paged
);
query_posts( $args ); ?>
<div class="wrapper clearfix">
<div class="main">
<div class="content <?php mh_content_class(); ?>">
<?php mh_before_page_content(); ?>
<?php dynamic_sidebar('pages-1'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!-- <?php the_content(); ?> -->
<article <?php post_class(); ?>>
<div class="loop-wrap loop-layout2">
<div class="clearfix">
<div class="loop-thumb">
<a href="<?php the_permalink(); ?>">
<?php if( get_field('business_logo') ): ?>
<?php $image = wp_get_attachment_image_src(get_field('business_logo'), 'loop'); ?>
<img src="<?php echo $image[0]; ?>" alt="<?php the_field('business_logo');?>" data-thumb="<?php echo $thumb[0]; ?>" />
<?php else: echo '<img src="' . get_template_directory_uri() . '/images/noimage_300x225.png' . '" alt="No Picture" />'; ?>
<?php endif; ?>
</a>
</div>
<div class="loop-content">
<header>
<h3 class="loop-title"><?php the_title(); ?></h3>
</header>
<?php if (get_field('business_description')): ?>
<?php $text_to_trim = get_field('business_description');
echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?>
<?php endif; ?>
<?php if (get_field('business_paying_desc')): ?>
<?php $text_to_trim = get_field('business_paying_desc');
echo '<div class="mh-excerpt">'. davide_excerpt($text_to_trim) . '</div>' . "\n" ; ?>
<?php endif; ?>
</div>
</div>
</div>
</article>
<?php dynamic_sidebar('pages-2'); ?>
<?php endwhile; ?>
<!-- <?php wp_reset_postdata(); ?> -->
<?php wp_reset_query(); ?>
<?php endif; ?>
<div class="sb-widget home-2 home-wide">
<h4 class="widget-title">Latest Updates</h4>
<ul class="cp-widget clearfix">
<?php query_posts( $args2 ); ?>
<?php if (have_posts()) : $i=1; while (have_posts() && ($i<=10)) : the_post(); ?>
<li class="cp-wrap cp-small clearfix">
<div class="cp-thumb">
<a href="<?php the_permalink(); ?>">
<?php if( get_field('business_logo') ): ?>
<?php $image = wp_get_attachment_image_src(get_field('business_logo'), 'cp_small'); ?>
<img width="70" height="53" src="<?php echo $image[0]; ?>" alt="<?php the_field('business_logo');?>" data-thumb="<?php echo $thumb[0]; ?>" class="attachment-cp_small wp-post-image" />
<?php endif; ?>
</a></div>
<div class="cp-data">
<p class="cp-widget-title"><?php the_title(); ?></p>
</div>
</li>
<?php $i++; ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif;?>
</ul>
</div>
<div class="sb-widget home-2 home-wide">
<?php echo do_shortcode('[rev_slider 620_100]'); ?>
</div>
<?php if (isset($options['comments_pages']) ? $options['comments_pages'] : false) : ?>
<section>
<?php comments_template(); ?>
</section>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php mh_second_sb(); ?>
</div>
<?php get_footer(); ?>
Pls help me with this because I am really clueless.
One good news is that if I check the array with print_r($termsObjects[0]); I can see properly the output.
I guess I should use a foreach somehow, but I don't know where to put my hands on.
Thank you to anyone who can help me with this.
Regards
..your question is a bit broad...but the gist of what you need to do:
to pull the variables from the url
$query = explode('&', $_SERVER['QUERY_STRING']);
$params = array();
foreach( $query as $param ){
list($name, $value) = explode('=', $param);
$params[urldecode($name)][] = urldecode($value);
}
now you will have a params array i've no idea what your urls will look like, but say its '
postterm1 = italian, postterm2 = chinese, etc
$array['taxquery'] = array();
$array['taxquery'][relation]= 'OR';
foreach ($param as $key=>$value) {
$array['taxquery'][]=array(
'taxonomy' => 'restaurants',
'field' => 'slug',
'terms' => $value
);
}
this will build the query you see below, just delete 'tax_query' array and insert the var $array instead. It should work but i haven't tested it so play around with the format if needed.
your custom query (i think you want multi taxonomies but not all?)
Use WP_query:
$args= array(
'post_type' => 'activties',
'tax_query' => array(
'relation'=>'OR',
array(
'taxonomy' => 'restaurants',
'field' => 'slug',
'terms' => 'italian'
),
array(
'taxonomy' => 'restaurants',
'field' => 'slug',
'terms' => 'chinese'
)
),
);
ref: http://codex.wordpress.org/Class_Reference/WP_Query
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.