2017-10-02 14 views
0

ソリューションを必要と私は、このようなカスタムポストタイプ登録:私のfront-page.phpワードプレスは、私はWordPressのテーマを開発していた

register_post_type('servicesDetails', array(
    'labels' => array(
     'name' => 'Services Details', 
     'add_new_item' => 'Add New Post' 
    ), 
    'public' => true, 
    'supports' => array('title', 'editor', 'thumbnail') 
)); 

を、私はこのようなHTMLをコーディングされました:

<div class="container"> 
    <?php 
    $servicesDetails = new WP_Query(array(
     'post_type' => 'servicesDetails' 
    )); 

    while ($servicesDetails->have_posts()) : 
     ?> 
     <div class="row"> 
      <?php 
      for ($counter = 0; $counter < 3; $counter++) : 
       $servicesDetails->the_post(); 
       ?> 
       <div class="col-sm-4" id="featurePost"> 
        <a href="<?php the_permalink(); ?>"><h3><?php the_title(); ?></h3></a> 
        <p><?php the_content(); ?></p> 
       </div> 
       <?php 
      endfor; 
      ?> 
     </div> 
     <?php 
    endwhile; 
    ?> 
    </div> 

それはsingle.phpテンプレートからテンプレートを取っていると私はsingle.phpを削除すると、それはTEMを使用している、私は、single-servicesDetails.phoという名前のファイルを開いていますワードプレスは、そのファイルからテンプレートを取っていませんプレートはindex.phpです。

誰にもこの問題の解決策がありますか?あなたが登録ポスト関数を呼び出している

+0

? –

答えて

0
//create custom post type 

function create_post_type() { 
    register_post_type('acme_product', 
    array(
     'labels' => array(
     'name' => __('Products'), 
     'singular_name' => __('Product') 
    ), 
     'public' => true, 
     'has_archive' => true, 
    ) 
); 
} 
add_action('init', 'create_post_type'); 

/* on the front-page.php - This will change the default front page ie your homepage. 
posts_per_page does the loop counts for you. You do not need the for loop again in your code. 
*/ 
<div class="container"> 
<div class="row"> 
<?php 
$args = array('post_type' => 'product', 'posts_per_page' => 10); 
$loop = new WP_Query($args); 
while ($loop->have_posts()) : $loop->the_post(); ?> 

    <div class="col-sm-4" id="featurePost"> 
     <a href="<?php the_permalink(); ?>"><h3><?php the_title(); ?></h3></a> 
     <p><?php the_content(); ?></p> 
    </div> 
<?php endwhile; ?> 

</div> 

関連する問題