2016-12-22 8 views
0

"Resource"라는 이름의 게시물을위한 메타 박스를 만들었습니다. 여기서 나는 백엔드에서 사전 정의 된 select 요소로부터 값을 선택할 수 있습니다. 저장 한 후 프론트 엔드에 표시합니다. 이미지를 참조하십시오. wordpress에서 the_tags() 또는 the_category()와 같은 함수를 만드는 방법은 무엇입니까?

Front-end

Back-end

는 지금이 태그, 저자 및 카테고리와 같은 일을합니다. 클릭하면 동일한 값으로 선택된 모든 게시물이 표시됩니다. 그러나 어디서부터 시작해야할지 모른다.

나는 메타 박스 플러그인을 사용 function.php

add_filter('rwmb_meta_boxes', 'resource_meta_box'); 
function resource_meta_box($meta_boxes) { 

    $meta_boxes[] = array(
     'id'   => 'resource_box', 
     'title'  => esc_html__('Resource'), 
     'post_types' => array('post'), 
     'context' => 'side', 
     'priority' => 'high', 
     'autosave' => true, 

     // List of meta fields 
     'fields'  => array(
      // RESOURCE BOX 
      array(
       'name'  => esc_html__(''), 
       'id'   => "resource", 
       'type'  => 'select', 
       // Array of 'value' => 'Label' pairs for select box 
       'options'  => array(
        'Item 1' => esc_html__('Item 1'), 
        'Item 2' => esc_html__('Item 2'), 
        'Item 3' => esc_html__('Item 3'), 
        'Item 4' => esc_html__('Item 4'), 
        'Item 5' => esc_html__('Item 5'), 
       ), 
       // Placeholder of Select. 
       'placeholder' => esc_html__('None') 
      ) 
     ) 
    ); 
    return $meta_boxes; 
} 

에 다음 코드를했고, 그것을 필요로하는 다음 코드는 사전에 <?php echo rwmb_meta('resource'); ?>

감사를 표시합니다.

+0

게시물에 대한 메타 데이터를 가져 오는 방법을 읽은 다음 한 번에 알려줍니다. 방해가되는 경우 돌아와서 시도한 것을 보여 주지만 노력을했다고 표시해야합니다. –

+0

https://developer.wordpress.org/reference/functions/get_post_meta/ –

답변

0

사용자 정의 분류 체계로 이동해야합니다. 사용자가 필요로하는 기능을 가지고 있기 때문입니다. 게시물 또는 '대한 (예 :'게시물을 '텍스트 포스트 형 슬러그와'당신의 포스트 형-슬러그 '를 대체 여기

$labels = array(
    'name'      => _x('Resources', 'taxonomy general name', 'textdomain'), 
    'singular_name'    => _x('Resource', 'taxonomy singular name', 'textdomain'), 
    'search_items'    => __('Search Resources', 'textdomain'), 
    'popular_items'    => __('Popular Resources', 'textdomain'), 
    'all_items'     => __('All Resources', 'textdomain'), 
    'parent_item'    => null, 
    'parent_item_colon'   => null, 
    'edit_item'     => __('Edit Resource', 'textdomain'), 
    'update_item'    => __('Update WResource', 'textdomain'), 
    'add_new_item'    => __('Add New Resource', 'textdomain'), 
    'new_item_name'    => __('New Resource Name', 'textdomain'), 
    'separate_items_with_commas' => __('Separate Resources with commas', 'textdomain'), 
    'add_or_remove_items'  => __('Add or remove Resources', 'textdomain'), 
    'choose_from_most_used'  => __('Choose from the most used Resources', 'textdomain'), 
    'not_found'     => __('No Resources found.', 'textdomain'), 
    'menu_name'     => __('Resources', 'textdomain'), 
); 

$args = array(
    'hierarchical'   => true, 
    'labels'    => $labels, 
    'show_ui'    => true, 
    'show_admin_column'  => true, 
    'update_count_callback' => '_update_post_term_count', 
    'query_var'    => true, 
    'rewrite'    => array('slug' => 'resource'), 
); 

register_taxonomy('resource', 'your-post-type-slug', $args); 

테마 functions.php의 file.enter 코드를 넣고 주어진 코드를 붙여 넣습니다 페이지 '등)에 해당하는 분류 유형을 지정합니다.

는 '자원'분류

get_terms('resource', array(
    'hide_empty' => false, 
)); 

(새로 추가 된 분류법에 의해) 템플릿 파일, 필터링 쇼에 archive.php에서 분류-resource.php를 작성 후 목록에서 생성 된 모든 용어를 검색 할 울부 짖는 코드를 사용 .

the_terms(get_the_ID(),'resource', $before, $sep, $after);을 사용하면 루프 내부의 특정 게시물에 대해 선택된 리소스를 표시 할 수 있습니다.

+0

안녕하세요, 세부 코드 및 설명 주셔서 감사합니다. 잘 작동하지만 URL도 생성되지만 문제는 404 찾을 수없는 페이지를 보여주는 것입니다. –