2014-03-19 53 views
0

我有一個wordpress網站,它顯示博客頁面中標題,圖片,描述和閱讀更多按鈕的最新帖子。當閱讀更多按鈕被點擊時,它將被定向到single.php並且它的工作正常。自定義帖子類型的單獨頁面模板

現在我創建了一個新的自定義帖子類型,稱爲「產品」,我可以在其中添加產品。它具有類似於single.php的佈局,但我需要在產品的單個頁面中進行一些更改和其他操作。所以,我打算創建一個單獨的文件single_product.php。

我想要的產品下的讀取更多按鈕,自動鏈接到single_product.php的博客文章鏈接到的single.php

下面是代碼:single.php中

<?php get_header(); ?> 
<!--BEGIN #content --> 
<div id="content"> 
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
<!--BEGIN .hentry --> 
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>"> 
<!--BEGIN .post-header--> 
<div class="post-header"> 
    <div class="inner"> <span class="meta-category"> 
    <?php the_category(', '); ?> 
    </span> 
    <h1 class="post-title"> 
     <?php the_title(); ?> 
     <?php $format = get_post_format(); ?> 
     <?php if ($format == "image" || $format == "gallery" || $format == "video") : ?> 
     <span class="icon"><img src="<?php echo get_template_directory_uri(); ?>/images/icon-<?php echo $format; ?>.png" alt="<?php echo $format; ?>" /></span> 
     <?php endif; ?> 
    </h1> 
    <span class="meta-published"> 
    <?php _e('Posted', 'engine') ?> 
    <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' '. __('ago', 'engine'); ?></span> <span class="meta-author"> 
    <?php _e('by', 'engine') ?> 
    <?php the_author_posts_link(); ?> 
    </span> </div> 

    <!--END .post-header --> 
    </div> 

    <!--BEGIN .featured-image --> 
    <div class="featured-image <?php echo get_post_format(); ?>"> 
    <?php if (get_post_format() == 'video' && get_post_meta(get_the_ID(), 'dt_video', true) != '') : ?> 
    <?php 
       global $wp_embed; 
       $video_url = get_post_meta(get_the_ID(), 'dt_video', true); 
       $video_embed = $wp_embed->run_shortcode('[embed width="620"]'.$video_url.'[/embed]'); 
       ?> 
    <div id="video-<?php the_ID(); ?>"><?php echo $video_embed; ?></div> 
    <?php elseif (get_post_format() == 'gallery') : ?> 

    <!--BEGIN #slides --> 
    <div id="single-slides" class="clearfix"> 
    <?php 

        $args = array(
         'orderby' => 'menu_order', 
         'post_type'  => 'attachment', 
         'post_parent' => get_the_ID(), 
         'post_mime_type' => 'image', 
         'post_status' => null, 
         'numberposts' => -1, 
        ); 

        $attachments = get_posts($args); 

        ?> 
     <?php if ($attachments) : ?> 
     <div class="slides_container"> 
     <?php foreach ($attachments as $attachment) : ?> 
     <?php 
     $format = get_post_format(); 
     $src = wp_get_attachment_image_src($attachment->ID, 
     array('9999','9999'), false, ''); 
          $src = $src[0]; 
    $image = dt_resize($attachment->ID, $src, 620, '', true);?> 
     <div> <span class="overlay-icon overlay-<?php echo $format; ?>"> 
     <a rel="group-<?php the_ID(); ?>" 
     title="<?php echo $attachment->post_title;?>"  
     class="colorbox-<?php echo $format; ?>" 
     href="<?php echo $src; ?>"></a></span> 
     <img height="<?php echo $image['height']; ?>" 
     width="<?php echo $image['width']; ?>" 
     alt="<?php echo apply_filters('the_title', $attachment->post_title); ?>" 
         src="<?php echo $image['url']; ?>" 
         /> </div> 
     <?php endforeach; ?> 
     </div> 

     <!--BEGIN .slide-cntrols--> 
     <div id="slide-controls"> <a href="#" class="next">Next</a> 
     <a href="#" class="prev">Prev</a> 
     <!--END .slide-cntrols--> 
     </div> 
     <?php endif; ?> 
     <!--END #slides --> 
     </div> 
     <?php elseif (has_post_thumbnail() && get_option('dt_blog_image') != 'false'):?> 
     <?php $thumb = get_post_thumbnail_id(get_the_ID()); 
    $image = dt_resize($thumb, '', 620, '', true); 
    echo '<img src="'.$image['url'].'" width="'.$image['width'].'"  
     height="'.$image['height'].'" alt="" />';?> 
     <?php endif; ?> 
     <!--END .featured-image --> 
     </div> 
     <!--BEGIN .post-content --> 
     <div class="post-content"> 
     <?php the_content(); ?> 
     <!--END .post-content --> 
     </div> 

     <!--BEGIN .post-footer--> 
     <div class="post-footer"> <span class="meta-published"> 
     <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')).'  
    '. __('ago', 'engine'); ?></span> <span class="meta-comments"> 
     <?php comments_number(__('No Comments', 'engine'), 
     __('1 Comment','engine'), __('% Comments', 'engine')); ?> 
     </span> 
     <!--END .post-footer--> 
     </div> 
     <!--END .hentry--> 
     </div> 
     <?php comments_template('', true); ?> 
     <?php endwhile; else : ?> 
     <p> 
     <?php _e('No posts found', 'engine'); ?> 
     </p> 
     <?php endif; ?> 
     </div> 
     <!-- #content --> 
     <?php get_sidebar(); ?> 
     <?php get_footer(); ?> 

我該怎麼做?

+1

重命名'single_product.php'到'single-yourcustomposttypeslug.php' –

+0

只有重命名才能做到?我需要做其他事嗎? – Shareer

+0

不,這個工作適合你嗎? –

回答

3

嘗試使用這樣的:

1. archive-{post_type}.php 
2. single-{post_type}.php 

檢查this link瞭解更多詳情。

1

參見Page Hierarchy的圖像中:

enter image description here

  1. archive- {custompost_type_name} .PHP/*像歸檔brand.php */

  2. single- {custompost_type_type} .php/*如單brand.php */

  3. taxonomy- {custompost_type_category_name} .PHP/*像 分類法brand_category.php */

相關問題