我有一个自定义后循环页面,其中有几个类别。 其中一个类别是“即将推出”,我不希望该类别的任何内容可点击。 我正在尝试为此目的添加一个类,但不知道如何将该类添加到“即将推出”类别中。
这是自定义帖子类型的代码
//Well Pads
function wellpad_custom_taxonomies() {
$labels = array(
'name' => 'Well Pads Categories',
'singular_name' => 'Well Pad Category',
'search_items' => 'Search Well Pads Categories',
'all_items' => 'All Well Pads Category',
'parent_item' => 'Parent Well Pads Category',
'parent_item_colon' => 'Parent Well Pads Category:',
'edit_item' => 'Edit Well Pads Category',
'update_item' => 'Update Well Pads Category',
'add_new_item' => 'Add New Well Pads Category',
'new_item_name' => 'New Well Pads Category',
'menu_name' => 'Well Pads Categories'
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_in_rest' => false, // Make available in Edit Post block options (for testing).
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'wellpad_category' )
);
register_taxonomy('wellpad_category', null, $args);
}
function wellpad_custom_post_type () {
$labels = array (
'name' => 'Well Pads',
'singular_name' => 'Well Pad',
'add_new' => 'Add New Well Pad',
'all_items' => 'All Well Pads',
'add_new_item' => 'Add A Well Pad',
'edit_item' => 'Edit Well Pad',
'new_item' => 'New Well Pad',
'view_item' => 'View Well Pad',
'parent_item_colon' => 'Parent Item',
'rewrite' => array( 'slug' => 'wellpad' )
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_rest' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_icon' => 'dashicons-location-alt',
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail',
'custom-fields',
'revisions',
'page-attributes'
),
'taxonomies' => array('wellpad_category', 'post_tag'),
'menu_position' => 10,
'exclude_from_search' => false
);
register_post_type('wellpad', $args);
}
// Priority must be a higher number than register_taxonomy.
// register_post_type must be called after register_taxonomy.
add_action( 'init', 'wellpad_custom_post_type', 20 );
function myplugin_query_vars( $qvars ) {
$qvars[] = 'wellpad_category_filter';
return $qvars;
}
add_filter( 'query_vars', 'myplugin_query_vars' );
我是否需要添加查询来添加“即将推出”类别的类?
您如何创建自定义后循环页面?如果您正在使用页面构建器,请添加您正在使用的构建器。
以下解决方案假设您正在为“自定义循环页面”使用自定义代码:
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$categories = get_the_category(); // Get the categories for the current post
$is_coming_soon = false;
foreach ( $categories as $category ) {
if ( strtolower( $category->name ) === 'coming soon' ) {
$is_coming_soon = true;
break;
}
}
?>
<div class="post <?php echo $is_coming_soon ? 'coming-soon' : ''; ?>">
<?php if ( $is_coming_soon ) : ?>
<span class="post-title"><?php the_title(); ?></span> <!-- Not clickable -->
<?php else : ?>
<a href="<?php the_permalink(); ?>" class="post-title"><?php the_title(); ?></a> <!-- Clickable -->
<?php endif; ?>
</div>
<?php
endwhile;
endif;
?>