0
我一直在一起拼湊各種示例的各個部分,但似乎無法將我的頭圍繞在此。定期發佈第一個(降序),然後在WP搜索中定製發佈類型(按字母順序排列)
我定期發佈博客帖子(新聞),我希望顯示最新的最新消息,然後是我希望在新聞下面分組的自定義帖子類型(商家)。我正在使用Sage,這是我的第一個主題。
這是迄今爲止我初學代碼:
<?php get_template_part('templates/page', 'header'); ?>
<?php if (!have_posts()) : ?>
<div class="alert alert-warning">
<?php _e('Sorry, no results were found.', 'sage'); ?>
</div>
<?php get_search_form(); ?>
<?php endif; ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php $post_type = get_post_type_object(get_post_type()); ?>
<?php $type = get_post_type(); ?>
<?php if ($type == 'post') { ?>
<h2>News Results</h2>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div>
<a href="<?php the_permalink(); ?>">
<?php $cats=get_the_category(); ?>
<?php echo $cats[0]->cat_name; ?>
</a>
</div>
<div>
<h3><?php the_title(); ?></h3>
<div class="result-excerpt">
<?php if (has_excerpt($post->ID)) {
echo the_excerpt();
} else {
echo get_excerpt();
} ?>
</div>
</div>
</article>
<?php } elseif ($type == 'business') { ?>
<h2>Business Results</h2>
<article <?php post_class(); ?>>
<header>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php if (get_post_type() === 'post') { get_template_part('templates/entry-meta'); } ?>
</header>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div>
<a href="<?php the_permalink(); ?>">
<?php $cats=get_the_category(); ?>
<?php echo $cats[0]->cat_name; ?> -
<?php the_title(); ?>
</a>
<h3><?php echo the_sub_field('title'); ?></h3>
<?php if(get_sub_field('content')): ?>
<div class="result-excerpt">
<?php echo custom_field_excerpt(); ?>
</div>
<?php endif; ?>
</article>
<?php } ?>
<?php endwhile; ?>
<?php endif; ?>
因此,您是否爲商業文章和未使用的類別創建了特定的自定義帖子類型? –
要求澄清,以便我可以爲您量身定製建議的修補程序。 –
CPT業務包含類別和標籤。 – James