2014-09-24 252 views
0

我是新來的wordpress。我想創建一個新的自定義帖子類型,並已生成此代碼,並且它可以工作。循環自定義帖子類型

<? 
// Register Custom Post Type 
function berita_post_type() { 

$labels = array(
    'name'    => _x('berita-internal', 'Post Type General Name', 'text_domain'), 
    'singular_name'  => _x('berita-internal', 'Post Type Singular Name', 'text_domain'), 
    'menu_name'   => __('Berita Internal', 'text_domain'), 
    'parent_item_colon' => __('Parent Item:', 'text_domain'), 
    'all_items'   => __('Semua Berita', 'text_domain'), 
    'view_item'   => __('Lihat', 'text_domain'), 
    'add_new_item'  => __('Tambah', 'text_domain'), 
    'add_new'    => __('Tambah Berita', 'text_domain'), 
    'edit_item'   => __('Edit Berita', 'text_domain'), 
    'update_item'   => __('Update berita', 'text_domain'), 
    'search_items'  => __('Search berita', 'text_domain'), 
    'not_found'   => __('Not found', 'text_domain'), 
    'not_found_in_trash' => __('Not found in Trash', 'text_domain'), 
); 
$args = array(
    'label'    => __('berita-internal', 'text_domain'), 
    'description'   => __('berita-internal', 'text_domain'), 
    'labels'    => $labels, 
    'supports'   => array('title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions',), 
    'taxonomies'   => array('category', 'post_tag'), 
    'hierarchical'  => false, 
    'public'    => true, 
    'show_ui'    => true, 
    'show_in_menu'  => true, 
    'show_in_nav_menus' => true, 
    'show_in_admin_bar' => true, 
    'menu_position'  => 5, 
    'can_export'   => true, 
    'has_archive'   => true, 
    'exclude_from_search' => false, 
    'publicly_queryable' => true, 
    'rewrite'    => true, 
    'capability_type'  => 'page', 
); 
register_post_type('internal', $args); 

} 

// Hook into the 'init' action 
add_action('init', 'berita_post_type', 0); 

?> 

它的工作原理,但我如何顯示該自定義帖子類型中的所有帖子? 這將是就像一個普通的博文 感謝

回答

1

試試這個:創建新的文件每日新聞-Internal.php上傳到當前主題目錄

<?php 
/** 
* Template Name: Berita Internal 
* 
* @package WordPress 
*/ 

get_header(); ?> 

<div id="primary" class="site-content"> 
    <div id="content" role="main"> 

     <?php 
     $args=array(
      'post_type' => 'berita-internal', 
      'post_status' => 'publish', 
      'posts_per_page' => -1, 
      'caller_get_posts'=> 1); 

     $my_query = null; 
     $my_query = new WP_Query($args); 
     if($my_query->have_posts()) { 
      while ($my_query->have_posts()) : $my_query->the_post(); ?> 
      <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> 
      <?php 
      endwhile; 
     } 
     wp_reset_query(); // Restore global post data stomped by the_post(). 
     ?> 

    </div><!-- #content --> 
</div><!-- #primary --> 

<?php get_sidebar(); ?> 
<?php get_footer(); ?> 

然後去可溼性粉劑管理員創建新頁面(頁面級>添加新的)。看右邊,

去去dropdow模板 - >選擇Berita內部。然後保存並查看頁面。

1

那就最好創建一個新的模板,並使用下面的代碼來創建新的模板,然後創建新的一頁,這個模板分配給您的 頁嘗試這樣的事情

<?php 
/** 
* Template Name: Your Template name 
* 
*/ 
?> 

<?php get_header(); ?> 

     <div id="container"> 
      <div id="content"> 

<?php 
$type = 'berita-internal'; //change product type as per your custom post type 
$args=array(
    'post_type' => $type, 
    'post_status' => 'publish', 
    'posts_per_page' => -1, 
    'caller_get_posts'=> 1 

$my_query = null; 
$my_query = new WP_Query($args); 
if($my_query->have_posts()) { 
    while ($my_query->have_posts()) : $my_query->the_post(); ?> 
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> 
    <?php 
    endwhile; 
} 
wp_reset_query(); // Restore global post data stomped by the_post(). 
?> 


</div><!-- #content --> 
     </div><!-- #container --> 

<?php get_sidebar(); ?> 
<?php get_footer(); ?> 
+0

您需要在您的主題中創建新模板,我的意思是創建新的.php文件 – 2014-09-24 06:48:59

+0

您是否在頁面頂部添加了'Template Name:berita',如上例所示? – 2014-09-24 07:54:54

相關問題