我都快抓狂了,希望有人能帮帮我。我已经创建了一个自定义的帖子类型- 事件。
add_action('init', 'event'); // Events post-type
function event()
{
register_taxonomy_for_object_type('category', 'event');
register_taxonomy_for_object_type('post_tag', 'event');
register_post_type('event',
array(
'labels' => array(
'name' => __('Events', 'event'),
'singular_name' => __('Event', 'event'),
'add_new' => __('Add New', 'event'),
'add_new_item' => __('Add New Event', 'event'),
'edit' => __('Edit', 'event'),
'edit_item' => __('Edit Event', 'event'),
'new_item' => __('New Event', 'event'),
'view' => __('View Event', 'event'),
'view_item' => __('View Event', 'event'),
'search_items' => __('Search Event', 'event'),
'not_found' => __('No Events found', 'event'),
'not_found_in_trash' => __('No Events found in Trash', 'event')
),
'public' => true,
'publicly_queryable' => true,
'hierarchical' => true,
'has_archive' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
),
'taxonomies' => array(
'post_tag',
'category'
) // Add Category and Post Tags support
));
}
在Events.php模板文件中,对于Events页面,我使用:
查询post类型<?php query_posts('post_type=event&order=ASC&post_status=future'); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
...
</a>
</li>
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
然后是single-event.php当然
所以,如果我在浏览器中登录到wordpress,我可以访问单个事件页面,没有问题。但是,如果我退出登录,它们会返回404页面,以及我试图打开它们的任何其他计算机。我没有运行缓存软件,每次调整后我都访问了permallinks页面,并且.htaccess文件看起来很好。
任何想法?
在你的Events.php模板中有:
<?php query_posts('post_type=event&order=ASC&post_status=future'); ?>
post_status
被设置为"future
",所以你只会看到那些帖子,如果你登录。如果您已注销,您将看不到它们,即使它们已发布,除非它们的发布日期早于您查看事件的日期。
有几个关于register_post_type
的论点,我不认为这可能会有什么不同。试试这些:
'public' => true, // Master
'publicly_queryable' => false, // must be set to true to use in a template
'exclude_from_search' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'custom_type', 'with_front' => false ),
'has_archive' => 'custom_type',
'capability_type' => 'post',
'hierarchical' => false,
尝试呼叫:
flush_rewrite_rules();
:后register_post_type('event',
array(
'labels' => array(
'name' => __('Events', 'event'),
'singular_name' => __('Event', 'event'),
'add_new' => __('Add New', 'event'),
'add_new_item' => __('Add New Event', 'event'),
'edit' => __('Edit', 'event'),
'edit_item' => __('Edit Event', 'event'),
'new_item' => __('New Event', 'event'),
'view' => __('View Event', 'event'),
'view_item' => __('View Event', 'event'),
'search_items' => __('Search Event', 'event'),
'not_found' => __('No Events found', 'event'),
'not_found_in_trash' => __('No Events found in Trash', 'event')
),
'public' => true,
'publicly_queryable' => true,
'hierarchical' => true,
'has_archive' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
),
'taxonomies' => array(
'post_tag',
'category'
) // Add Category and Post Tags support
));
或者将其添加到参数数组中:
'rewrite' => array( 'slug' => 'event','with_front' => FALSE),
最后是:
register_post_type('event',
array(
'labels' => array(
'name' => __('Events', 'event'),
'singular_name' => __('Event', 'event'),
'add_new' => __('Add New', 'event'),
'add_new_item' => __('Add New Event', 'event'),
'edit' => __('Edit', 'event'),
'edit_item' => __('Edit Event', 'event'),
'new_item' => __('New Event', 'event'),
'view' => __('View Event', 'event'),
'view_item' => __('View Event', 'event'),
'search_items' => __('Search Event', 'event'),
'not_found' => __('No Events found', 'event'),
'not_found_in_trash' => __('No Events found in Trash', 'event')
),
'public' => true,
'publicly_queryable' => true,
'hierarchical' => true,
'has_archive' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
),
'taxonomies' => array(
'post_tag',
'category'
),
'rewrite' => array( 'slug' => 'event','with_front' => FALSE),
));
您是否检查了帖子状态?如果事件发布为定时发布,则只有登录用户才能访问该页面。否则他们会看到404页面