我在 wordpress 后端创建了一个自定义帖子类型,名为 Demo-questions。而且我还设置了一个首页,然后我成功地从该类型中获取了我所有自定义帖子的列表,但我需要帮助在页面上仅显示一个帖子。只有一个。谁的永久链接已打开。例如,如果我打开
http://gaincafe.com/education/?demo_questions=first-demo-question
然后我只想显示名为 first-demo-question 的演示问题自定义帖子。提前感谢您的帮助。
我在 wordpress 后端创建了一个自定义帖子类型,名为 Demo-questions。而且我还设置了一个首页,然后我成功地从该类型中获取了我所有自定义帖子的列表,但我需要帮助在页面上仅显示一个帖子。只有一个。谁的永久链接已打开。例如,如果我打开
http://gaincafe.com/education/?demo_questions=first-demo-question
然后我只想显示名为 first-demo-question 的演示问题自定义帖子。提前感谢您的帮助。
使其single-{your custompost type name}.php
优先呈现该自定义帖子类型的单个帖子
因此,在您的情况下single-demo-questions.php
,您可以将所有代码从 single.php 复制到此,并可以根据您的需要进行修改
// 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(']]>', ']]>', $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];}
?>