我有一个带有自定义分类法的自定义帖子类型。
我当前正在显示按日期排序的所有帖子,标题为日期,位于使用此代码的所有帖子上方:
<?php
$years = $wpdb->get_results( "SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type = \'press\' AND post_status = \'publish\' GROUP BY year DESC" );
foreach ( $years as $year ) {
$posts_this_year = $wpdb->get_results( "SELECT ID, post_title FROM wp_posts WHERE post_type = \'press\' AND post_status = \'publish\' AND YEAR(post_date) = \'" . $year->year . "\'" );
echo \'<div id="press-year">\' . $year->year . \'</div>\';
foreach ( $posts_this_year as $post ) {
echo \'<div id="small_gridbox1">\';
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), thumbnail, false);
echo \'<div id="small_gridbackground" style="background-image: url(\';
echo $src[0];
echo \')"> </div>
<a href="\';
the_field(\'pdflink\');
echo \'" target="_blank"> <div id="small_gridcontent">
<div class="small_title">\';
the_title();
echo \'<div class="job_title">\';
the_field(\'title\');
echo \'</div></div>
<div class="small_sub">\';
echo str_replace(\' \', \'\', get_field(\'sub_heading\'));
echo \'</div>
</div>
</a>
</div>\';
}
}
?>
我似乎无法在归档页面上仅获得具有特定分类法的帖子。理想情况下,我希望使用我拥有的代码,但如何将其与我过去成功使用的代码结合起来:
<?php $term = get_term_by( \'slug\', get_query_var( \'term\' ),
get_query_var( \'taxonomy\' ) ); ?>
有人能提供一些见解吗?