2013-10-11 283 views
-1

我在wordpress後端創建了一個名爲Demo-questions的自定義帖子類型。並且我還設置了首頁,然後我成功獲得了該類型的所有自定義帖子的列表,但是我需要幫助只在頁面上顯示一個帖子。只有一個。誰的永久鏈接已打開。例如,如果我打開如何在wordpress中顯示自定義帖子類型的單獨帖子

http://gaincafe.com/education/?demo_questions=first-demo-question

的話,我只是想表明一個名爲第一演示問題演示問題自定義後。提前感謝您的幫助。

回答

0

使single-{your custompost type name}.php將被最優先渲染你的自定義後類型

所以單後,你的情況single-demo-questions.php你可以從single.php中複製所有代碼這一點,可根據自己的需要修改

0

// wp-content\themes\twentysixteen by default twentysixteen theme in wordpress // 
 
make single-{your custompost type name}.php it will be given top priority to render your single post of that custom post type. 
 

 
single-page.php change to this format single-demo.php // demo is custom post type name. 
 

 
//how to get custom post type id in in single-demo.php /// 
 

 
<?php 
 
/** 
 
* The template for displaying all single posts and attachments 
 
* 
 
* @package WordPress 
 
* @subpackage Twenty_Sixteen 
 
* @since Twenty Sixteen 1.0 
 
*/ 
 
get_header(); 
 
?> 
 

 
    
 
<?php 
 
$Id= get_the_ID(); 
 
    $content_post = get_post($Id); 
 
    $content = $content_post->post_content; 
 
    $content = apply_filters('the_content', $content); 
 
$content = str_replace(']]>', ']]&gt;', $content); 
 
$post_image_id = get_post_thumbnail_id($post_to_use->ID); 
 
if ($post_image_id) {$thumbnail = wp_get_attachment_image_src($post_image_id,array(350,350));if ($thumbnail) (string)$thumbnail = $thumbnail[0];} 
 

 

 
?>

+0

任何解釋? – NatNgs

+0

如何從父頁面的單個自定義頁面中獲取任何內容和縮略圖圖片這是有用的代碼 –

相關問題