2017-02-07 7 views
0

したがって、子テーマテンプレートの内部でプラグイン関数を使用する方法

私はプラグイン機能を実行するテンプレートを作成しようとしています。 これは私が作ろうとしているテンプレートです。 これはエラーです。

警告:C:\ www \ htdocs \ FCN-GIT \ wp-content \ themes \ Avada-Child-Theme \ single-wpt_test.phpのforeach()引数が無効です。ライン39

Fatal error: Call to undefined method WP::doAction() in C:\www\htdocs\FCN-GIT\wp-content\themes\Avada-Child-Theme\single-wpt_test.php on line 44

<?php 
/** 
* Template Name: Test 
* 
* @package WordPress 
* @subpackage Avada 
* @since 2016 
*/ 
?> 

<?php 
// Can be overriden in your theme as entry-content-wpt-test-fill-form.php 

/* @var $answerIdName string */ 
/* @var $answerIndex integer */ 
/* @var $isShowContent boolean */ 
/* @var $formAttributes array */ 
/* @var $content string */ 
/* @var $subTitle string */ 
/* @var $shortDescription string */ 
/* @var $test WpTesting_Model_Test */ 
/* @var $questions WpTesting_Model_Question[] */ 
/* @var $isFinal boolean */ 
/* @var $isMultipleAnswers boolean */ 
/* @var $submitButtonCaption string */ 
/* @var $stepsCounter string */ 
/* @var $wp WpTesting_WordPressFacade */ 
/* @var $hiddens array */ 
?> 
<div class="wpt_test fill_form"> 

<?php if ($isShowContent): ?> 
<div class="content"> 
    <?php echo $content ?> 
</div> 
<?php endif ?> 

<div class="content"><form 
<?php foreach ($formAttributes as $key => $value):?> 
    <?php echo $key ?>="<?php echo htmlspecialchars(is_array($value) ? json_encode($value) : $value) ?>" 
<?php endforeach ?>> 
<?php if ($subTitle): ?><h2 class="subtitle"><?php echo $subTitle ?></h2><?php endif ?> 
<?php if ($shortDescription): ?><div class="short-description"><?php echo $wp->autoParagraphise($shortDescription) ?></div><?php endif ?> 
<?php $wp->doAction('wp_testing_template_fill_form_questions_before') ?> 
<?php foreach($questions as $q => $question): /* @var $question WpTesting_Model_Question */ ?> 
    <?php $wp->doAction('wp_testing_template_fill_form_question_before', $question, $q) ?> 
    <div class="question"> 

     <div class="title"> 
      <span class="number"><?php echo $q+1 ?>.</span><span class="title"><?php echo $question->getTitle() ?> 
      <?php $wp->doAction('wp_testing_template_fill_form_label_end', array('required' => true)) ?></span> 
     <?php if (!$isMultipleAnswers): ?> 
      <input type="hidden" name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="" /> 
     <?php endif ?> 
     </div> 

    <?php foreach($question->buildAnswers() as $a => $answer): /* @var $answer WpTesting_Model_Answer */ ?> 
     <?php $answerId = 'wpt-test-question-' . $question->getId() . '-answer-' . $answer->getId() ?> 

     <div class="answer"> 

      <label for="<?php echo $answerId ?>"> 
       <input type="<?php echo $isMultipleAnswers ? 'checkbox' : 'radio' ?>" id="<?php echo $answerId ?>" 
        data-errormessage="<?php echo $isMultipleAnswers 
         ? __('Please select at least one answer.', 'wp-testing') 
         : __('Please choose only one answer.', 'wp-testing') ?>" 
        <?php if (0 == $a): ?>required="required" aria-required="true"<?php endif ?> 
        name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="<?php echo $answer->getId() ?>" /> 
       <?php echo $answer->getTitleOnce() ?> 
      </label> 

     </div> 
     <?php if ($isMultipleAnswers) {$answerIndex++;} ?> 
    <?php endforeach ?> 

    </div> 
    <?php $wp->doAction('wp_testing_template_fill_form_question_after', $question, $q) ?> 
    <?php if (!$isMultipleAnswers) {$answerIndex++;} ?> 
<?php endforeach ?> 
<?php $wp->doAction('wp_testing_template_fill_form_questions_after') ?> 

<?php if($isFinal): ?> 
    <p> 
     <input type="submit" class="button" value="<?php echo $submitButtonCaption ?>" /> 
     <?php if($stepsCounter): ?><span class="steps-counter"><?php echo $stepsCounter ?></span><?php endif ?> 
    </p> 
<?php else: ?> 
    <div class="wpt_warning"> 
     <h4><?php echo __('Test is under construction', 'wp-testing') ?></h4> 
     <p><?php echo __('You can not get any results from it yet.', 'wp-testing') ?></p> 
    </div> 
<?php endif ?> 
<?php foreach($hiddens as $name => $value): ?><input type="hidden" name="<?php echo htmlspecialchars($name) ?>" value="<?php echo htmlspecialchars($value) ?>" /><?php endforeach ?> 
</form></div> 

</div> 

答えて

0

に私はこの問題を解決するために管理しますが、プラグインのデフォルトのテンプレートを上書き、私は、とても基本的に、1の違い2つのテンプレートを持っている私のホームページのコードを持つテンプレートを必要に応じて別のページのために。

ホームページに変更があり、他のページには表示されず、デフォルトのテーマテンプレートが使用されます。

ここでは、プラグインコードを使用して2つのテンプレートを使用するという私の解決策がありました。

<?php 
// Can be overriden in your theme as entry-content-wpt-test-fill-form.php 

/* @var $answerIdName string */ 
/* @var $answerIndex integer */ 
/* @var $isShowContent boolean */ 
/* @var $formAttributes array */ 
/* @var $content string */ 
/* @var $subTitle string */ 
/* @var $shortDescription string */ 
/* @var $test WpTesting_Model_Test */ 
/* @var $questions WpTesting_Model_Question[] */ 
/* @var $isFinal boolean */ 
/* @var $isMultipleAnswers boolean */ 
/* @var $submitButtonCaption string */ 
/* @var $stepsCounter string */ 
/* @var $wp WpTesting_WordPressFacade */ 
/* @var $hiddens array */ 
?> 

<?php if (is_front_page()): ?> 
    <div class="home-health-insight wpt_test fill_form"> 

    <div class="answers"> 
     <div class="content"> 
     <form 
     <?php foreach ($formAttributes as $key => $value):?> 
      <?php echo $key ?>="<?php echo htmlspecialchars(is_array($value) ? json_encode($value) : $value) ?>" 
     <?php endforeach; ?>> 
     <?php if ($isShowContent): ?><div class="content" style="margin:0;"><?php echo $content ?></div><?php endif ?>  
     <?php if ($shortDescription): ?><div class="short-description"><?php echo $wp->autoParagraphise($shortDescription) ?></div><?php endif ?> 
     <?php $wp->doAction('wp_testing_template_fill_form_questions_before') ?> 
     <div class="question">  
      <div class="question-titles"> 
      <div class="question-labels"> 
       <label class="answerlbl" for="<?php echo $answerId ?>"> 
       None of the time 
       </label> 
       <label class="answerlbl" for="<?php echo $answerId ?>"> 
       Rarely 
       </label> 
       <label class="answerlbl" for="<?php echo $answerId ?>"> 
       Some of the time 
       </label> 
       <label class="answerlbl" for="<?php echo $answerId ?>"> 
       Often 
       </label> 
       <label class="answerlbl" for="<?php echo $answerId ?>"> 
       All of the time 
       </label>  
      </div> 
      </div>        
      <?php foreach($questions as $q => $question): /* @var $question WpTesting_Model_Question */ ?> 
      <?php $wp->doAction('wp_testing_template_fill_form_question_before', $question, $q) ?> 

      <div class="title"> 
       <span class="question-title" style="width:100%;"><?php echo $question->getTitle() ?> 
       <?php $wp->doAction('wp_testing_template_fill_form_label_end', array('required' => true)) ?></span> 
       <?php if (!$isMultipleAnswers): ?> 
        <input type="hidden" name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="" /> 
       <?php endif ?> 
       </div> 
       <div class="answer-block"> 
       <?php foreach($question->buildAnswers() as $a => $answer): /* @var $answer WpTesting_Model_Answer */ ?> 
        <?php $answerId = 'wpt-test-question-' . $question->getId() . '-answer-' . $answer->getId() ?> 

        <div class="answer"> 

        <input type="<?php echo $isMultipleAnswers ? 'checkbox' : 'radio' ?>" id="<?php echo $answerId ?>" 
        data-errormessage="<?php echo $isMultipleAnswers 
        ? __('Please select at least one answer.', 'wp-testing') 
        : __('Please choose only one answer.', 'wp-testing') ?>" 
        <?php if (0 == $a): ?>required="required" aria-required="true"<?php endif ?> 
        name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="<?php echo $answer->getId() ?>" /> 

        </div> 
        <?php if ($isMultipleAnswers) {$answerIndex++;} ?> 
       <?php endforeach ?> 
       </div> 
       <?php $wp->doAction('wp_testing_template_fill_form_question_after', $question, $q) ?> 
       <?php if (!$isMultipleAnswers) {$answerIndex++;} ?> 
      <?php endforeach ?> 
      </div> 

      <?php $wp->doAction('wp_testing_template_fill_form_questions_after') ?> 

      <?php if($isFinal): ?> 
      <p> 
       <input type="submit" class="button" value="<?php echo $submitButtonCaption ?>" /> 
       <?php if($stepsCounter): ?><span class="steps-counter"><?php echo $stepsCounter ?></span><?php endif ?> 
      </p> 
      <?php else: ?> 
      <div class="wpt_warning"> 
       <h4><?php echo __('Test is under construction', 'wp-testing') ?></h4> 
       <p><?php echo __('You can not get any results from it yet.', 'wp-testing') ?></p> 
      </div> 
      <?php endif ?> 
      <?php foreach($hiddens as $name => $value): ?><input type="hidden" name="<?php echo htmlspecialchars($name) ?>" value="<?php echo htmlspecialchars($value) ?>" /><?php endforeach ?> 
     </form> 
     </div> 
    </div> 

    </div> 
<?php else: ?> 
    <div class="wpt_test fill_form"> 

    <?php if ($isShowContent): ?> 
    <div class="content"> 
     <?php echo $content ?> 
    </div> 
    <?php endif ?> 

    <div class="content"><form 
    <?php foreach ($formAttributes as $key => $value):?> 
     <?php echo $key ?>="<?php echo htmlspecialchars(is_array($value) ? json_encode($value) : $value) ?>" 
    <?php endforeach ?>> 
    <?php if ($subTitle): ?><h2 class="subtitle"><?php echo $subTitle ?></h2><?php endif ?> 
    <?php if ($shortDescription): ?><div class="short-description"><?php echo $wp->autoParagraphise($shortDescription) ?></div><?php endif ?> 
    <?php $wp->doAction('wp_testing_template_fill_form_questions_before') ?> 
    <?php foreach($questions as $q => $question): /* @var $question WpTesting_Model_Question */ ?> 
     <?php $wp->doAction('wp_testing_template_fill_form_question_before', $question, $q) ?> 
     <div class="question"> 

      <div class="title"> 
       <span class="number"><?php echo $q+1 ?>.</span><span class="title"><?php echo $question->getTitle() ?> 
       <?php $wp->doAction('wp_testing_template_fill_form_label_end', array('required' => true)) ?></span> 
      <?php if (!$isMultipleAnswers): ?> 
       <input type="hidden" name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="" /> 
      <?php endif ?> 
      </div> 

     <?php foreach($question->buildAnswers() as $a => $answer): /* @var $answer WpTesting_Model_Answer */ ?> 
      <?php $answerId = 'wpt-test-question-' . $question->getId() . '-answer-' . $answer->getId() ?> 

      <div class="answer"> 

       <label for="<?php echo $answerId ?>"> 
        <input type="<?php echo $isMultipleAnswers ? 'checkbox' : 'radio' ?>" id="<?php echo $answerId ?>" 
         data-errormessage="<?php echo $isMultipleAnswers 
          ? __('Please select at least one answer.', 'wp-testing') 
          : __('Please choose only one answer.', 'wp-testing') ?>" 
         <?php if (0 == $a): ?>required="required" aria-required="true"<?php endif ?> 
         name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="<?php echo $answer->getId() ?>" /> 
        <?php echo $answer->getTitleOnce() ?> 
       </label> 

      </div> 
      <?php if ($isMultipleAnswers) {$answerIndex++;} ?> 
     <?php endforeach ?> 

     </div> 
     <?php $wp->doAction('wp_testing_template_fill_form_question_after', $question, $q) ?> 
     <?php if (!$isMultipleAnswers) {$answerIndex++;} ?> 
    <?php endforeach ?> 
    <?php $wp->doAction('wp_testing_template_fill_form_questions_after') ?> 

    <?php if($isFinal): ?> 
     <p> 
      <input type="submit" class="button" value="<?php echo $submitButtonCaption ?>" /> 
      <?php if($stepsCounter): ?><span class="steps-counter"><?php echo $stepsCounter ?></span><?php endif ?> 
     </p> 
    <?php else: ?> 
     <div class="wpt_warning"> 
      <h4><?php echo __('Test is under construction', 'wp-testing') ?></h4> 
      <p><?php echo __('You can not get any results from it yet.', 'wp-testing') ?></p> 
     </div> 
    <?php endif ?> 
    <?php foreach($hiddens as $name => $value): ?><input type="hidden" name="<?php echo htmlspecialchars($name) ?>" value="<?php echo htmlspecialchars($value) ?>" /><?php endforeach ?> 
    </form></div> 

    </div> 
<?php endif ?> 
関連する問題