我想从categroy循环中排除当前的“页面”(而不是帖子):
文件:
档案文件php,内容。php,内容首页。php(页面模板)
我已经创建了2个类别(archive.php),并将2篇文章关联到每个类别。我将“content top page.php”放在类别的顶部。这些都是“页面”,我不想更改它们(标题、帖子缩略图和特定文本,仅此而已)。
问题是:
模板页面与其他帖子一起显示在循环中。每个类别的当前模板页都包含在中。我在模板页面中使用特定的ACF变量。
如果你有什么想法,谢谢你。
Archive.php
$exclude_ids = array( 45, 36 );
$my_query = new WP_Query(array(
\'exclude\' => $exclude_ids,
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
));
<section style="padding:10px!important;">
if ( have_posts() ) : ?>
<section>
<?php
get_template_part(\'content\',\'top-page\');
?>
</section><!-- .section -->
<div class="row">
<?php while ( $my_query->have_posts() ) : $my_query->the_post();
<div class="col-lg-3">
<?php get_template_part( \'template-parts/content\',
get_post_format() );
?>
</div>
<?php endwhile; ?>
</div>
<?php endif;
wp_reset_postdata(); ?>
</section>
content-top-page.php (template page)
<?php if ( has_category(\'my_category_1\') ): ?>
<div class="row">
<div class="col-lg-12">
<h1><strong><?php the_title(); ?></strong></h1>
</div>
<div class="col-sm-12 col-md-6 col-lg-6 col-xl-6" style="background-color:red;">
<img src="<?php get_field(\'top_profil_featured_image\'); ?>" />
</div>
<div class="col-lg-6">
<?php echo get_field(\'top_profil_content\'); ?>
</div>
</div>
<?php endif ?>
<?php if ( has_category(\'my_category_2\') ): ?>
<div class="row">
<div class="col-lg-12">
<h1><strong><?php the_title(); ?></strong></h1>
</div>
<div class="col-sm-12 col-md-6 col-lg-6 col-xl-6" style="background-color:green;">
<img src="<?php get_field(\'top_profil_featured_image\'); ?>" />
</div>
<div class="col-lg-6">
<?php echo get_field(\'top_profil_content\'); ?>
</div>
</div>
<?php endif ?>
content.php
<article id="post-<?php the_ID(); ?>" class="" <?php post_class(); ?> style="border:1px solid #6f3fa5;">
<?php
if ( !is_single() && has_post_thumbnail() ) { ?>
<div class="entry-img">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(\'blog-way-common\'); ?></a>
</div>
<?php
}
?>
<div class="entry-content">
<?php
if( is_single() ){
the_content( sprintf(
/* translators: %s: Name of current post. */
wp_kses( __( \'Continue reading %s <span class="meta-nav">→</span>\', \'blog-way\' ), array( \'span\' => array( \'class\' => array() ) ) ),
the_title( \'<span class="screen-reader-text">"\', \'"
</span>\', false )) );
wp_link_pages( array(
\'before\' => \'<div class="page-links">\' . esc_html__( \'Pages :\', \'blog-way\' ),
\'after\' => \'</div>\',
) );
} else {
echo excerpt_custom_length(20);
}
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->