admin管理员组文章数量:1332873
I need some help from someone who can look at the code template below and see what I apparently still have wrong. I've been working on getting a template setup for a site that is using TwentyTwelve as its base. This template would call up all post types but using only a common single category. I thought I had it nailed in tests two years ago, but the client is now getting around to using it and reports that it isn't working.
An answer that someone else gave was to use this in the args:
$args = array(
'post_type' => 'any', //or use cpt slug as string, or array of strings if multiple
'category_name' => 'budgeting', // <-- EDIT CATEGORY SLUG HERE. Must be all lower case and with dashes if there are any, exactly as it appears in the category listings. Be careful not to delete the single quotes!
);
Example: A template that uses the category of "budgeting" shows 24 posts, and the site has 20 regular posts and 6 of another post type using that same category. So it seems to be working because it is showing more than 20 posts. The template:
<?php
/**
* Template Name: Category - Budgeting
*
* ^^^ THIS IS THE TEMPLATE TITLE THAT APPEARS IN THE DROPDOWN ON A PAGE EDITING AREA. KEEP THE ASTERISKS.
*
* The template for displaying all pages.
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
get_header();
$args = array(
'post_type' => 'any', //or use cpt slug as string, or array of strings if multiple
'category_name' => 'budgeting', // <-- EDIT CATEGORY SLUG HERE. Must be all lower case and with dashes if there are any, exactly as it appears in the category listings. Be careful not to delete the single quotes!
);
// This query should now only have the post_type in the args above.
$this_query = new WP_Query( $args ); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php
if ( $this_query->have_posts() ) : ?>
<header class="archive-header">
<h1 class="archive-title">
<?php
if ( is_day() ) :
printf( __( 'Daily Archives: %s', 'twentytwelve' ), '<span>' . get_the_date() . '</span>' );
elseif ( is_month() ) :
printf( __( 'Monthly Archives: %s', 'twentytwelve' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentytwelve' ) ) . '</span>' );
elseif ( is_year() ) :
printf( __( 'Yearly Archives: %s', 'twentytwelve' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentytwelve' ) ) . '</span>' );
else :
_e( 'Budget Articles List', 'twentytwelve' ); // <-- EDIT THE PAGE TITLE HERE. BE CAREFUL NOT TO EDIT THE SINGLE QUOTE MARKS!!!
endif;
?>
</h1>
</header><!-- .archive-header -->
<?php while ( $this_query->have_posts() ) : $this_query->the_post();
$post_id = get_the_ID(); // In case you need to use the post ID
?>
<?php if( has_post_thumbnail() ): ?>
<header class="entry-header">
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
</h1>
<span class="post-meta">Author <?php the_author_posts_link(); ?> | <?php the_time('F jS, Y'); ?> | <?php the_category(', '); ?></span>
</header><!-- .entry-header -->
<div class="entry-summary">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?></a><?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php endif; ?>
<?php
endwhile;
wordpress_numeric_post_nav();
wp_reset_postdata();
endif;
?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
When we try this with another category of "College Education", there are 8 regular posts and 4 of another post type in the system with 'college-education' as the slug. But only 8 posts show up in the page when the template is used with that slug in place. We should be seeing twelve posts. So this isn't working.
Could someone advise me if you see something that shouldn't work? We thought we had nailed this but it's not working.
Link for the Budget page on the actual site: /
Link for the College Education page on the actual site: /
本文标签: categoriesCustom query using one category that is used in all custom post types
版权声明:本文标题:categories - Custom query using one category that is used in all custom post types 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742309425a2450567.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论