如何在wordpress中显示自定义帖子类型的单个帖子

时间:2013-10-11 17:14:53

标签: wordpress

我在wordpress后端创建了一个自定义帖子类型,名为Demo-questions。我也设置了一个首页,然后我成功获得该类型的所有自定义帖子的列表,但我需要帮助只显示页面上的一个帖子。只有一个。谁的永久链接已被打开。例如,如果我打开

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

然后我只想显示名为first-demo-question的演示问题自定义帖子。谢谢你的帮助。

2 个答案:

答案 0 :(得分:0)

make single-{your custompost type name}.php将优先渲染自定义帖子类型的单个帖子

因此,在您的情况single-demo-questions.php中,您可以将所有代码从single.php复制到此,并可以根据您的需要进行修改

答案 1 :(得分: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];}


?>