2014-09-24 4 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

이 시도 : 새로운 파일 berita-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(); ?> 

에 업로드 만드는 그런 WP - 관리자로 이동하여 새 페이지를 만들 (페이지 -> 새로운 추가). 오른쪽을 봐,

이동 드롭 다운 Template-> select Berita Internal. 그런 다음 페이지를 저장하고 봅니다.

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 파일을 만듭니다. –

+0

위 예제와 같이 페이지 상단에'Template Name : berita'을 추가 했습니까? –

관련 문제