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 C++ /QT 内存权限的判断函数列举
  • ¥15 深度学习GFnet理解问题
  • ¥15 单细胞小提琴堆叠图代码
  • ¥80 LS dyna mpp并行报错
  • ¥50 升级strust2版本到2.3.15.1后使用ognl3.0.6.jar windows环境中没有问题,但部署到linux环境报错
  • ¥15 vue页面,node封装接口
  • ¥15 求TMS320F280039C工程模板!
  • ¥15 delphi+fastreport实现分组补空打印问题
  • ¥15 使用python把两台mysql数据库服务器数据导出和导入
  • ¥15 NodeBB论坛配置Apache Solr中文搜索引擎的详细教程