php - Wordpress 自定义帖子类型使用首页

标签 php wordpress permalinks

编辑请忽略此主题。结果这个问题根本与 wordpress 或永久链接无关,而是来自一个愚蠢的 voeding mistrals。

我定义了一个 wordpress 自定义帖子类型,如下所示:

add_action('init', 'fotoalbums_register_posttype');  
function fotoalbums_register_posttype() {  
register_post_type( 'fotoalbum-item' , array(  
    'labels' => array(
                'name'          => 'Fotoalbums',
                'singular_name' => 'Fotoalbum',
                'menu_name'     => 'Fotoalbums',
                'all_items'     => 'Overzicht',
                'add_new'       => 'Nieuw album',
                'add_new_item'  => 'Nieuw album',
                'edit_item'     => 'Bewerk album',
                'new_item'      => 'Nieuw album',
                'view_item'     => 'Bekijk album',
                'search_items'  => 'Zoek albums',
                'not_found'     => 'Niet gevonden',         
    ),  
    'public' => true,  
     'has_archive' => false,
    'show_ui' => true,  
    'capability_type' => 'page',  
    'hierarchical' => false,   
    'supports' => array('title', 'editor') ,
     'menu_position' => 31,
     'rewrite' => array( 'slug' => 'fotoalbum', 'with_front' => true)
   )//end array
); //end register_post_type()
}//end function fotoalbums_register_posttype()  

然后我创建了一个名为 single-fotoalbum-item.php 的页面,该页面支持显示此帖子类型的单个项目。 奇怪的是,事实并非如此。可能与永久链接有关,因为:

the_permalink(); gives http://kdans.net/e-motion-2012/ and results in a 404 error

the permalink in wp-admin shows http://kdans.net/fotoalbum/e-motion-2012/ , which displays the frontpage template (!!)

我多次保留永久链接,但一些遇到此问题的人不断返回。我的错误在哪里?

正如评论中所建议的那样,这里是重写规则。

http://kdans.net/fotoalbum/e-motion-2012/ gives:
index.php?fotoalbum-item=$matches[1]&page=$matches[2] (source fotoalbum-item)
index.php?pagename=$matches[1]&page=$matches[2] (source: page)
index.php?attachment=$matches[1] (source: post)

http://kdans.net/e-motion-2012/ gives
index.php?pagename=$matches[1]&page=$matches[2] (source: page)
index.php?name=$matches[1]&page=$matches[2] (source: post)

最佳答案

我认为问题出在这里:'rewrite' => array( 'slug' => 'fotoalbum', 'with_front' => true)

因此,当发生重写时,它会从 fotoalbum-item 更改为 fotoalbum。这就是为什么 url 是 http://kdans.net/fotoalbum/e-motion-2012/ 的原因而不是 http://kdans.net/fotoalbum-item/e-motion-2012/

因此,您创建了自定义帖子,当您第一次重写时,即从设置->永久链接中将 slug 更改为 fotoalbum。

尝试将其更改为:'rewrite' => array( 'slug' => 'fotoalbum-item', 'with_front' => true) 并重新刷新永久链接。它应该是工作。

关于php - Wordpress 自定义帖子类型使用首页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19634948/

相关文章:

mysql - 优化查询 - 从同一个子查询中选择 COUNT 和 SUM

php - 与 PHP 的永久链接

wordpress - Wordpress:你最喜欢的永久链接结构 - 高效/seo友好

php - CodeIgniter 搜索查询

php - JMS 序列化程序。创建 2 种具有 "one-to-many"关系的模型序列化方式

php - 代码和 SQL 查询中有什么错误?为什么网页上没有任何显示?

php - 从远程服务器运行 PHP 代码?

WordPress的永久链接不停留

php - myrocks (mariadb + rocksdb) php 字符集

php - Cakephp 3 多模型操作的事务管理