2017-10-05 4 views
1

사용자 정의 게시 유형 이름 Dog Food Quiz를 WordPress 플러그인으로 만들었습니다. 게시물 유형이 표시되지만 single-dog-food-quiz.php 파일을 만들면 페이지에 아무 것도 표시되지 않습니다. 개 식품 quiz.php를 들어Wordpress Single 사용자 정의 게시 유형 페이지가 작동하지 않습니다.

:

<?php get_header(); ?> 
<?php while (have_posts()) : the_post(); ?> 
    <main id="site-main" class="main-page article-page" data-ad-slots="top,rightrail1,stickyrightrail2,bottom,oop"> 
     <div class="inner dog-food-quiz-top"> 
      <section id="content"> 
       <h1>Can my Dog Eat This?</h1> 
       <div class="dfq-hero"> 
        <img src="/img/dog-food-quiz/hero.jpg" alt="dog with 2 bowls"> 
       </div><!-- dog food quiz hero --> 
       <p class="dfq-intro">Think again before tossing your dog that last bit from your dinner plate. How well do you know which human foods are okay for your canine friend to eat?</p> 
       <span class="dfq-disclaimer">*Always consult your veterinarian to help you understand the best diet for your dog.</span> 
       <div class="progress-container"><progress value="0" max="100" id="progressBar" style="width: 0%"></progress></div> 
       <div class="food-module"> 
        <div class="food-box"> 
         <span class="food-title">Apples?</span> 
         <img src="/img/dog-food-quiz/redapple200.jpg" alt="apple"> 
         <span class="correct" style="display: none;">Correct!</span> 
         <span class="incorrect" style="display: none;">Incorrect!</span> 
        </div><!-- food box --> 
        <div class="food-description" style="display: none;"> 
         <span>Remove the seeds and stem - then you have a sweet treat</span> 
        </div><!-- food description --> 
        <a class="yes-answer correct">YES</a> 
        <a class="no-answer incorrect">NO</a> 
       </div><!-- food module -->   
       <div class="results-block" style="display:none;"> 
        <div class="score-card"> 
         <h3 class="results-title"></h3><!-- results-title --> 
         <span class="results-comment"></span><!-- results-comment --> 
         <img src="" class="results-image" alt=""> 
        </div><!-- score-card --> 
        <div class="results-description"> 
         <p class="mobile-results"></p> 
         <p class="tablet-results"></p> 
         <div class="addthis_inline_share_toolbox"></div> 
        </div><!-- results-description --> 
       </div><!-- results-block --> 

      <div class="ad callout"> 
       <span class="ad" id="dfp_bottom"></span> 
      </div> 
     <div class="grid m-2col"> 
      <h2 class="title"><small>Most Popular In</small> 
       Did You Know? 
      </h2> 
     </div> 
    </section> 
    <aside id="sidebar-right" class="sidebar no-tablet"> 
     <div id="sidebar-right-contents"> 
      <div class="ad desktop just-tablet-up" id="sidebar-right-ad-1"> 
       <span class="ad" id="dfp_rightrail1"></span> 
       </div> 
      </div> 
     </aside> 
    </div> 
    </main> 

    <?php endwhile; ?> 

    <?php get_footer(); ?> 

것은 내가 실종 : 여기

function dog_food_quiz() { 
    register_post_type('dog-food-quizzes', 
     array(
     'labels' => array(
      'name' => 'Dog Food Quiz', 
      'singular_name' => 'Dog Food Quiz', 
      'add_new' => 'Add New', 
      'add_new_item' => 'Add New Dog Food Quiz', 
      'edit' => 'Edit', 
      'edit_item' => 'Edit Dog Food Quiz', 
      'new_item' => 'New Dog Food Quiz', 
      'view' => 'View', 
      'view_item' => 'View Dog Food Quiz', 
      'search_items' => 'Search Dog Food Quizzes', 
      'not_found' => 'No Dog Food Quizzes found', 
      'not_found_in_trash' => 'No Dog Food Quizzes found in Trash', 
      'parent' => 'Parent Dog Food Quiz' 
     ), 

     'public' => true, 
     'menu_position' => 15, 
     'supports' => array('title', 'editor', 'comments', 'thumbnail', 'custom-fields'), 
     'taxonomies' => array(''), 
     'menu_icon' => 'dashicons-testimonial', 
     'has_archive' => true 
    ) 
); 
} 

add_action('init', 'dog_food_quiz'); 

add_filter('template_include', 'include_template_function', 1); 

function include_template_function($template_path) { 
    if (get_post_type() == 'dog_food_quizzes') { 
     if (is_single()) { 
     // checks if the file exists in the theme first, 
     // otherwise serve the file from the plugin 
     if ($theme_file = locate_template(array ('single-dog-food-quiz.php'))) { 
      $template_path = $theme_file; 
     } else { 
      $template_path = plugin_dir_path(__FILE__) . '/single-dog-food-quiz.php'; 
     } 
    } 
} 
    return $template_path; 
} 

단일 개 식품 quiz.php 코드입니다 여기에 내 코드입니다 여기에 뭔가있어? 머리말과 꼬리말과 빈 페이지가 있습니다. 도와주세요.

답변

0

템플릿의 이름을 single-dog-food-quizzes.php (예 : single-에 사용자가 올린 게시물 유형 이름 인 dog-food-quizzes으로 추가) 할 수 있습니다.

두 개 이상의 단어로 구성된 사용자 정의 게시 유형을 등록 할 때 하이픈이 아닌 밑줄을 사용하는 것이 좋습니다.

그런 다음 당신은 단일 쓰기 (단수) 개 식품 퀴즈 : 그래서 귀하의 경우 :이 같은 사용자 정의 포스트 유형 (CPT)에 이름을 경우

register_post_type('dog_food_quizzes')

+0

Jase에게 답변 해 주셔서 감사합니다. 내가 제안한 것처럼 파일의 이름을 변경했지만 여전히 표시하지 않습니다. – MikeL5799

+0

고마워요. 아직 아무 것도 시도하지 않았습니다. – MikeL5799

0

그것은 더 좋을 수 당신의 주제에 dog-food-quiz.php 파일.

For Custom Post Types, should the slug be singular or plural?

+0

왜 글을 쓰는지 이해할 수 없습니다. add_filter ('template_include', 'include_template_function', 1); ... 코드를 따르십시오. 맞으면 WordPress에서 자동으로 처리하므로이 작업을 수행 할 필요가 없습니다. 이것은 템플릿 계층 구조입니다. https://developer.wordpress.org/themes/basics/template-hierarchy/ –

+0

감사합니다. 나는 이름을 바꿨지 만 여전히 행운이 아니다. – MikeL5799

+0

'add_filter' 다음에 코드를 삭제 했습니까? –