自定义文章类型的自定义单页,wordpress
我刚刚了解了如何制作自定义的文章类型并将它们输出到页面上,我想知道是否可以为它们更改单个文章页面 例如,我可以设置一个自定义文章类型的自定义单页,wordpress,wordpress,posts,Wordpress,Posts,我刚刚了解了如何制作自定义的文章类型并将它们输出到页面上,我想知道是否可以为它们更改单个文章页面 例如,我可以设置一个单个news.php?如果是这样,PHP文件将如何格式化,WordPress如何知道如何使用该single-news.PHP文件?我只是想让他们把整篇文章都吐出来 谢谢 为此,您可以为single-news.php页面创建模板文件。 并通过wordpress查询获得您想要的帖子。 例如,您的single-news.php页面 <?php //Template Name: S
单个news.php
?如果是这样,PHP文件将如何格式化,WordPress如何知道如何使用该single-news.PHP文件
?我只是想让他们把整篇文章都吐出来
谢谢 为此,您可以为single-news.php页面创建模板文件。 并通过wordpress查询获得您想要的帖子。 例如,您的single-news.php页面
<?php
//Template Name: Single News
?>
<?php
//get your content
$args = array('category' =>'9','posts_per_page'=> 3);
$myposts = get_posts( $args );
global $post;
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
//go with your content
//跟着你的内容走
为此,您可以为single-news.php页面创建模板文件。
并通过wordpress查询获得您想要的帖子。
例如,您的single-news.php页面
<?php
//Template Name: Single News
?>
<?php
//get your content
$args = array('category' =>'9','posts_per_page'=> 3);
$myposts = get_posts( $args );
global $post;
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
//go with your content
//跟着你的内容走
创建CPT后,执行以下操作以显示CPT的单个帖子:
- 复制模板中的
文件,并将其重命名为single.php
(例如single-{post_type}.php
)single movie.php
- 刷新WordPress中的永久链接
- 现在,如果要显示可与args一起使用的CPT列表:
$args=array( ... “post_type”=>“电影” )
- 复制模板中的
文件,并将其重命名为single.php
(例如single-{post_type}.php
)single movie.php
- 刷新WordPress中的永久链接
- 现在,如果要显示可与args一起使用的CPT列表:
$args=array( ... “post_type”=>“电影” )
在wordpress中自定义帖子类型。基本四步
步骤1:文件路径位置:主题中的theme/function.php
在function.php中粘贴代码(注册自定义帖子类型)
步骤2:如何在wordpress模板页面中显示wordpress自定义帖子类型
: you can show anywhere in template page like this :
<?php $args = array( 'post_type' => 'services', 'posts_per_page' => 20 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="services-items">
<?php the_title();
if ( has_post_thumbnail( $post->ID ) ) {
echo '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( $post->post_title ) . '">';
echo get_the_post_thumbnail( $post->ID, 'thumbnail' );
echo '</a>'; }
?>
</div>
<?php endwhile; ?>
:您可以在模板页面中的任何位置显示以下内容:
第3步:创建新模板以显示单篇文章,如下所示
single-{custom post type name}.php
或
single-services.php
步骤4:在single-services.php文件中粘贴代码
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="main-post-div">
<div class="single-page-post-heading">
<h1><?php the_title(); ?></h1>
</div>
<div class="content-here">
<?php the_content(); ?>
</div>
<div class="comment-section-here"
<?php //comments_template(); ?>
</div>
</div>
<?php endwhile; ?>
这是一个带有单个贴子页面的自定义贴子类型示例。wordpress中的自定义贴子类型。基本四步
步骤1:文件路径位置:主题中的theme/function.php
在function.php中粘贴代码(注册自定义帖子类型)
步骤2:如何在wordpress模板页面中显示wordpress自定义帖子类型
: you can show anywhere in template page like this :
<?php $args = array( 'post_type' => 'services', 'posts_per_page' => 20 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="services-items">
<?php the_title();
if ( has_post_thumbnail( $post->ID ) ) {
echo '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( $post->post_title ) . '">';
echo get_the_post_thumbnail( $post->ID, 'thumbnail' );
echo '</a>'; }
?>
</div>
<?php endwhile; ?>
:您可以在模板页面中的任何位置显示以下内容:
第3步:创建新模板以显示单篇文章,如下所示
single-{custom post type name}.php
或
single-services.php
步骤4:在single-services.php文件中粘贴代码
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="main-post-div">
<div class="single-page-post-heading">
<h1><?php the_title(); ?></h1>
</div>
<div class="content-here">
<?php the_content(); ?>
</div>
<div class="comment-section-here"
<?php //comments_template(); ?>
</div>
</div>
<?php endwhile; ?>
这是一个带有单个贴子页面的自定义贴子类型示例。这太棒了!非常感谢你。请原谅我的无礼,但是你是一种在单个帖子页面(比如本例中的新闻)上吐出标题和内容的方式吗?这太棒了!非常感谢你。请原谅我的无礼,但是你是一种在单个帖子页面(比如本例中的新闻)上吐出标题和内容的方式吗?只是在这里添加注释。如果您已经创建了新的CPT,并且没有看到正确命名的模板的结果(包括
single.php
或single which.php
),请刷新永久链接。只需转到WP admin中的permalinks页面并点击“保存”。这个问题解决了9/10次。只需在这里添加一个注释。如果您已经创建了新的CPT,并且没有看到正确命名的模板的结果(包括single.php
或single which.php
),请刷新永久链接。只需转到WP admin中的permalinks页面并点击“保存”。这解决了问题9/10次。