My client wants to have the ability to call up a common category used in multiple custom post types. So if there is a common category of "budget", then a blog listing would come up with all the custom post types that have a category of "budget".
I read up on a few examples here of using args for different post types, and pieced them together on a custom template called "page-category-budgeting.php". This is in a child theme based on Twenty-twelve.
After testing and working through some debugging, I'm still without success. The latest error is "Parse error: syntax error, unexpected end of file in /home/acs10047/public_html/wp-content/themes/moneysmartfamily/page-category-budgeting.php on line 53"
But that is a blank line at the end of the code. I have nothing to go with to figure this out. Here is the template code. I must be missing something simple or overlooking how this should be set up. Could someone advise me as to what I'm missing? Thanks.
<?php
/**
* Template Name: Category - Budgeting
*
*
* 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' => array('post','media-appearance','members-archive','money-saving-tips','review'),
'posts_per_page' => '20',
);
$this_query = new WP_Query( $args ); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( $this_query->have_posts()) : $this_query->the_post(); {?>
<?php if( has_post_thumbnail() && ($cat == 'budget') ): ?>
<div class="tip-excerpt">
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
</h1>
<div class="entry-content">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?></a><?php the_excerpt(); ?>
</div>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
<?php // done the foreach statement ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
My client wants to have the ability to call up a common category used in multiple custom post types. So if there is a common category of "budget", then a blog listing would come up with all the custom post types that have a category of "budget".
I read up on a few examples here of using args for different post types, and pieced them together on a custom template called "page-category-budgeting.php". This is in a child theme based on Twenty-twelve.
After testing and working through some debugging, I'm still without success. The latest error is "Parse error: syntax error, unexpected end of file in /home/acs10047/public_html/wp-content/themes/moneysmartfamily/page-category-budgeting.php on line 53"
But that is a blank line at the end of the code. I have nothing to go with to figure this out. Here is the template code. I must be missing something simple or overlooking how this should be set up. Could someone advise me as to what I'm missing? Thanks.
<?php
/**
* Template Name: Category - Budgeting
*
*
* 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' => array('post','media-appearance','members-archive','money-saving-tips','review'),
'posts_per_page' => '20',
);
$this_query = new WP_Query( $args ); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( $this_query->have_posts()) : $this_query->the_post(); {?>
<?php if( has_post_thumbnail() && ($cat == 'budget') ): ?>
<div class="tip-excerpt">
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
</h1>
<div class="entry-content">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?></a><?php the_excerpt(); ?>
</div>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
<?php // done the foreach statement ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Share
Improve this question
asked Sep 21, 2019 at 12:58
David BorrinkDavid Borrink
234 bronze badges
0
3 Answers
Reset to default 0You are missing <?php endwhile; ?>
before the end of content div.
get_header();
$args = array('post_type' => array('post','media-appearance','members-archive','money-saving-tips','review'),
'posts_per_page' => '20',
);
$this_query = new WP_Query( $args ); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( $this_query->have_posts()) : $this_query->the_post(); {?>
<?php if( has_post_thumbnail() && ($cat == 'budget') ): ?>
<div class="tip-excerpt">
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
</h1>
<div class="entry-content">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?></a><?php the_excerpt(); ?>
</div>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
<?php // done the foreach statement ?>
<?php endwhile; ?> //ADDED CODE
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
This should work for you. I made some modifications to your code. you can message me if you need help with the layout of the elements.
get_header();
$args = array(
'category_name' => array(
'budget'
), // category_name (string) – use category slug.
);
// This query should now only have the post_type in the args above that are in the category budget.
$this_query = new WP_Query( $args ); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php
if ( $this_query->have_posts() ) :
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;
endif;
?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Another topic created here gave me the answer... very simple args structure now that I know.
get_header();
$args = array(
'post_type' => 'any', //or use cpt slug as string, or array of strings if multiple
'category_name' => 'budget', //use 'budget,premium' if you want posts with budget OR premium, use 'budget+premium' if you want budget AND premium.
);
// This query should now only have the post_type in the args above that are in the category budget.
$this_query = new WP_Query( $args ); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php
if ( $this_query->have_posts() ) :
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;
wp_reset_postdata();
endif;
?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745108656a4611710.html
评论列表(0条)