第一步在主题的function.php 中加入结构如下的代码块:

add_action( 'init', 'create_events' );
function create_events() {
  $labels = array(
    'name' => _x('Events', 'post type general name'),
    'singular_name' => _x('Event', 'post type singular name'),
    'add_new' => _x('Add New', 'Event'),
    'add_new_item' => __('Add New Event'),
    'edit_item' => __('Edit Event'),
    'new_item' => __('New Event'),
    'view_item' => __('View Event'),
    'search_items' => __('Search Events'),
    'not_found' =>  __('No Events found'),
    'not_found_in_trash' => __('No Events found in Trash'),
    'parent_item_colon' => ''
  );

  $supports = array('title', 'editor', 'custom-fields', 'revisions', 'excerpt');

  register_post_type( 'event',
    array(
      'labels' => $labels,
      'public' => true,
      'supports' => $supports
    )
  );
}

这些代码的意思是基于自带默认post类型进行变量名称的改变,这些会在后台看到如下:

接下来,基于single.php复制一份,改名为single-event.php作为event类型的内容展示模版

复制一份page.php ,改名为 page-events.php作为列出event条目的列表模版,page-event.php文件头部加上

Template Name: Events Template

具体格式:

<?php
/**
 * Template Name: Events Template
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */

get_header(); ?>

接下来,在列表里调用出event条目来,把下面代码加到post 调用的loop循环之前

<?php query_posts(array('post_type'=>'event')); ?>

加到

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

之前
然后在页面,创建eventlist,匹配刚才的page-event.php模版即可。

 

0 Comments

Leave a reply

电子邮件地址不会被公开。 必填项已用*标注

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

联系

微信ruinews360 微信公众号:小芳侠

Sending

Log in with your credentials

Forgot your details?