duanlong4890 2012-09-02 21:19
浏览 33
已采纳

Wordpress自定义帖子类型默认页面?

Ok I have made my custom post type and they work fine(code shown below). But I cant seem to make a default page for it for example example.com/php < how do I get that page. I can make pages like example.com/php/some page/ and they work fine.

$labels = array(
'name' => _x('PHP', 'post type general name'),
'singular_name' => _x('PHP', 'post type singular name'),
'add_new' => _x('Add New', 'PHP Page'),
);
$args = array(
'labels' => $labels,
'taxonomies' => array('post_tag'),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true, 
'show_in_menu' => true, 
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true, 
'hierarchical' => true,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'page-attributes')
 ); 
register_post_type('php',$args);

Thanks!

  • 写回答

1条回答 默认 最新

  • dongzhuo1733 2012-09-02 21:32
    关注

    I'm not sure if there is an intuitive way to do this in WordPress (you might want to check over at https://wordpress.stackexchange.com/). However, I'll explain how I have done this before.

    Create a new page template, say, php.php, with whatever you want the "default" page to do. Usually, I include a loop that only pulls from my custom post type.

    <?php
    /*
    Template Name: PHP Default Page
    */
    // ...
    query_posts("post_type=php");
    // ...
    ?>
    

    Then, create a page within the WordPress dashboard titled "PHP" (so it will have the permalink, http://example.com/php)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵