Php WordPress:自定义显示中的新型文章/页面

Php WordPress:自定义显示中的新型文章/页面,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我想创建一个类似于/news的页面,此页面需要具有与简单WordPress主题中的顶部/底部布局类似的内容: Title "is a link also to access the post/page" Space Content of 160 Chars not more 要简单地添加新新闻,请添加新帖子或页面,然后简单地将新帖子设置为普通帖子,并在新闻页面中选择一个选项 这也应该在RSS提要中,但我认为应该是这样,因为它们只是定制的帖子/页面,所以没有问题?这听起来像是你想要一个新的页面。

我想创建一个类似于
/news
的页面,此页面需要具有与简单WordPress主题中的顶部/底部布局类似的内容:

Title "is a link also to access the post/page"
Space
Content of 160 Chars not more
要简单地添加新新闻,请添加新帖子或页面,然后简单地将新帖子设置为普通帖子,并在新闻页面中选择一个选项


这也应该在RSS提要中,但我认为应该是这样,因为它们只是定制的帖子/页面,所以没有问题?

这听起来像是你想要一个新的页面。这应该像普通的文章或页面一样,但有自己的索引页面和后端管理屏幕。您需要使用创建帖子类型。在那之后,一切都是自动的。从法典中,作为参考:

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' );

参数可能有点混乱

这将让你开始,只需一些基础知识

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\u 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();
$args=array(
“post_type”=>“news”,
);
$thew_query=newwp_query($args);
while($the\u query->have\u posts()):
$the_query->the_post();
回声';
回音“”。获取内容()

",; 结束时; wp_reset_postdata();
你似乎想要一个自定义的帖子类型,但也需要一个160个字符的摘录,以便只显示160个字符?@DavidChase谢谢你的评论,这不是强制性的,只有160个字符,我只想指出它将是短文本,大约160个字符:)你在网站上的其他地方使用帖子吗?如果不是的话,你可以用那些?否则,请使用下面建议的自定义帖子类型