【发布时间】:2020-11-28 18:24:45
【问题描述】:
这是我在function.php 文件中的自定义帖子类型代码:
function muslim_taha_khedamate()
{
register_taxonomy_for_object_type('category', 'muslim'); // Register Taxonomies for Category
register_taxonomy_for_object_type('post_tag', 'muslim');
register_post_type('services', // Register Custom Post Type
array(
'labels' => array(
'name' => __('خدمات', 'muslim'), // Rename these to suit
'singular_name' => __('خدمت', 'muslim'),
'add_new' => __('اضافه کردن', 'muslim'),
'add_new_item' => __('خدمت جدید اضافه کنید.', 'muslim'),
'edit' => __('ویرایش', 'muslim'),
'edit_item' => __('ویرایش خدمت', 'muslim'),
'new_item' => __(' جدید', 'muslim'),
'view' => __('نمایش خدمت', 'muslim'),
'view_item' => __('نمایش خدمت', 'muslim'),
'search_items' => __('جستجوی خدمت', 'muslim'),
'not_found' => __('خدمتی پیدا نشد.', 'muslim'),
'not_found_in_trash' => __('خدمتی در زباله دان پیدا نشد.', 'muslim')
),
'public' => true,
'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
'has_archive' => true,
'menu_icon' => 'dashicons-admin-multisite',
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
), // Go to Dashboard Custom HTML5 Blank post for supports
'can_export' => true, // Allows export in Tools > Export
'taxonomies' => array(
'post_tag',
'category'
) // Add Category and Post Tags support
));
}
add_action('init', 'muslim_taha_khedamate'); // Add services Custom Post Type
这是我的查询:
<div class="row">
<?php
$args = array(
'post_type'=>'services',
'posts_per_page'=>3,
'orderby'=>'date',
'order'=>'ASC'
);
$service = new WP_Query($args);
?>
<?php
while($service->have_posts()): $service->the_post(); ?>
<div class="service col-md-4 col-sm-4">
<a href="<?php the_permalink(); ?>">
<div class="service-item card text-center mb-4">
<div class="image card-header text-center m-auto ">
<?php the_post_thumbnail( 'service',array('class'=>'img-fluid')) ?>
</div>
<div class="card-body pt-5">
<h3> <?php the_title(); ?></h3>
</div>
</div>
</a>
</div>
<?php endwhile; wp_reset_postdata();?>
</div>
我有一个单页 single-services.php,它必须为每个帖子显示单页,但不幸的是,当我单击每个自定义帖子类型时,它会给我错误 404 。
我有三个相同结构的自定义帖子类型,其中两个可以正常工作,但这个不行。
谁能帮帮我? 谢谢...
【问题讨论】:
标签: wordpress