2013-03-14 93 views
0

我想打一個網頁像/news,這個頁面需要有內容類似一個簡單的WordPress主題找到頂部/底部佈局:WordPress的:新型的自定義顯示的職位/頁

Title "is a link also to access the post/page" 
Space 
Content of 160 Chars not more 

只需簡單地添加新消息,添加新帖子或頁面,然後簡單地將新帖子設置爲普通帖子,然後選擇一個選項使其在新聞頁面中顯示。

這也應該在RSS飼料,但我認爲這將是他們只是定製的職位/頁面,所以沒有問題呢?

+1

好像你想要一個自定義帖子類型,但也是一個160的摘要只顯示160個字符? – 2013-03-14 14:14:10

+0

@DavidChase感謝您的評論,它不是強制性的只有160個字符,我只是想指出它將是短文本,或多或少的160個字符:) – Abude 2013-03-14 14:24:06

+0

您是否在您的網站的任何其他地方使用了帖子?如果不是,你可以使用這些?否則,請使用下面建議的自定義帖子類型。 – user2019515 2013-03-14 18:57:49

回答

1

這件事將讓你開始,隨着只是基礎知識

function custom_news() { 
register_post_type(
      'news', 
      array(
        'label' => __('News'), 
        'public' => true, 
        'show_ui' => true, 
        'capability_type' => 'post', 
        'menu_position' => 100, 
        'menu_icon' => 'path/to/icon', 
        'supports' => array(
           'editor', 
           'post-thumbnails', 
           'excerpts', 
           'custom-fields', 
           'comments', 
           'revisions') 
      ) 
    ); 
    register_taxonomy('articles', 'news', array('hierarchical' => true, 'label' => __('Articles'))); 

    } 
    add_action('init', 'custom_news'); 

,然後用WP_Query顯示在任何你想要的自定義文章:

$args = array(
    'post_type' => 'news', 
); 


$the_query = new WP_Query($args); 


while ($the_query->have_posts()) : 
$the_query->the_post(); 
echo '<a href="'.get_permalink($the_query->ID).'">' . get_the_title() . '</a>'; 
    echo '<p>' . get_the_content() . '</p>'; 
endwhile; 


wp_reset_postdata(); 
+0

肯定不用擔心 – 2013-05-18 15:19:29

1

這聽起來像是你想要一個Custom Post Type。這應該像普通的帖子或頁面一樣運行,但具有自己的索引頁面和後端管理屏幕。您需要使用register_post_type來創建帖子類型。之後,事情大都是自動的。從食品,作爲參考:

function codex_custom_init() { 
    $labels = array(
    'name' => 'Books', 
    'singular_name' => 'Book', 
    'add_new' => 'Add New', 
    'add_new_item' => 'Add New Book', 
    'edit_item' => 'Edit Book', 
    'new_item' => 'New Book', 
    'all_items' => 'All Books', 
    'view_item' => 'View Book', 
    'search_items' => 'Search Books', 
    'not_found' => 'No books found', 
    'not_found_in_trash' => 'No books found in Trash', 
    'parent_item_colon' => '', 
    'menu_name' => 'Books' 
); 

    $args = array(
    'labels' => $labels, 
    'public' => true, 
    'publicly_queryable' => true, 
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true, 
    'rewrite' => array('slug' => 'book'), 
    'capability_type' => 'post', 
    'has_archive' => true, 
    'hierarchical' => false, 
    'menu_position' => null, 
    'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments') 
); 

    register_post_type('book', $args); 
} 
add_action('init', 'codex_custom_init'); 

的參數可以是有點混亂。 Smashing Magazine has a post that should help

相關問題