所以我得到了这个模板,它最初按类别查询常规WP帖子,这样页面将显示“类别1”的类别名称作为标题,然后在标题下方显示该类别的帖子。与“2类”、“3类”等相同。
我正在尝试使用自定义的帖子类型,这样“帖子类型1”将成为标题,“帖子类型1”的帖子将位于标题下方。“Post type 2”也是一样的,等等。基本上是一样的,但是使用自定义的Post type而不是categories。
有了下面的代码,我将把标题放在它们的位置,但它们下面不会出现帖子。我有点受困于此,任何帮助都将不胜感激。
<?php
$args = array(\'_builtin\' => 0);
$post_types = get_post_types($args);
foreach ($post_types as $post_type) {
$post_type_link = get_post_type_archive_link( $post_type -> $post->ID );
?>
<div class="cat_list full">
<h3 class="h3title"><a href="<?php echo $post_type_link; ?>"><span><?php echo $post_type; ?></span></a></h3>
<div class="cat inline-block">
<ul class="switch half clearfix">
<?php
//$numberposts = admin::get_field_val(\'category_posts_nbr_front\');
$numberposts = admin_options::get_values( \'front_page\' , \'nr_post\' );
$post_number = 0;
$args = array(\'post_type\' => array( \'make\', \'model\', \'price\' ), \'showposts\'=>100, \'orderby\'=>\'date\');
$type_posts = new WP_Query($args); while($type_posts->have_posts()) : $type_posts->the_post();
if(get_post_thumbnail_id($post->ID) )
{
$post_img = wp_get_attachment_image(get_post_thumbnail_id($post->ID),\'62x62\',\'\' );
}
else
{
$post_img = get_first_image($post->ID,\'54x54\');
}
?>
<li <?php if($post_number % 2 == 1) echo "class=\'col_2\'" ?>>
<a href="<?php echo get_permalink( $post->ID ); echo \'#more\'; ?>"><?php echo $post_img; ?></a>
<h5><a href="<?php echo get_permalink($post->ID ); echo \'#more\'; ?>"><?php echo mb_substr(get_the_title( $post->ID ),0,BLOCK_TITLE_LEN); if(strlen(get_the_title( $post->ID ) ) > BLOCK_TITLE_LEN ) { echo \' ...\'; } ?></a></h5>
<span class="date"><?php echo mysql2date(get_option( \'date_format\' ) ,$post ->post_date) ?> //</span>
<span class="comm">
<?php if (\'open\' == $post->comment_status) { ?>
<a href="<?php echo get_permalink( $post->ID); echo \'#comments\'; ?>"><?php echo $post->comment_count.\' \'; if($post->comment_count ==1) {_e(\'Comment\');} else {_e(\' Comments\');} ?> </a>
<?php }else{ // comments are closed ?>
<a><?php _e( \'Comments Off\' ); ?></a>
<?php } ?>
</span>
</li>
<?php
$post_number ++;
endwhile;
?>
</ul>
<div class="no_bottom_border"></div>
</div>
</div> <!-- EOF cat_list-->
<?php
} /*EOF foreach categories*/ ?>
EDIT: 现在,它会在标题下方显示帖子,但不会根据自己的帖子类型将它们分开。换句话说,每一篇帖子都会显示在每一个帖子类型的标题下。有什么好处?