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)

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

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)