【问题标题】:Can not find custom post type single page in WordPress在 WordPress 中找不到自定义帖子类型单页
【发布时间】: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


    【解决方案1】:

    尝试自定义帖子类型单页

    &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title_attribute(); ?&gt;" &gt; &lt;/a&gt;

    【讨论】:

    • 我认为你应该为这个问题创建一个自定义插件来获取所有数据并将其传递到你想在那里使用的地方
    猜你喜欢
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 2011-03-20
    • 2014-05-21
    • 2014-06-17
    相关资源
    最近更新 更多