0

のようなページを作成したいのですが/news、このページには、単純なWordPressテーマにある上下のレイアウトに似たコンテンツが必要です。

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

新しいニュースを簡単に追加するには、新しい投稿またはページを追加してから、通常の投稿のように新しい投稿を作成し、そこにあるオプションを選択してニュースページに追加します。

これもRSSフィードに含める必要がありますが、カスタマイズされた投稿/ページであるため、問題はないと思います。

4

2 に答える 2

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();
于 2013-03-14T15:38:02.987 に答える
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 に役立つ投稿があります

于 2013-03-14T14:09:00.370 に答える