我是WordPress的新手。我已经为视频创建了一个自定义的帖子类型,但我不知道如何在页面中显示帖子类型。例如,我希望当用户添加视频时,他不必在发布视频时选择视频模板,当他们打开发布的视频时,页面将使用视频播放器打开,而不是打开页面。我想要的东西,像一个自定义的视频播放器准备好的东西,我所要做的就是给视频播放器的video.Already的网址,有视频播放器的代码。我该怎么做呢?
发布于 2012-09-20 23:29:23
要为所有自定义帖子类型的帖子或页面设置默认,您可以将模板文件命名为single-{your-cpt-name-here}.php或archive-{your-cpt-name-here}.php,当查看这些帖子或页面时,模板文件将始终默认使用此名称。
例如,在single-video.php中,您可以放入:
<?php query_posts( 'post_type=my_post_type' ); ?>或者进行自定义查询,以形成所需的输出:
<?php
$args = array(
'post_type' => 'my_post_type',
'post_status' => 'publish',
'posts_per_page' => -1
);
$posts = new WP_Query( $args );
if ( $posts -> have_posts() ) {
while ( $posts -> have_posts() ) {
the_content();
// Or your video player code here
}
}
wp_reset_query();
?>在上例所示的自定义循环中,Wordpress中有许多可用的 (如the_content)可供选择。
发布于 2013-12-02 03:40:36
在Functions.php中编写代码
function create_post_type() {
register_post_type( 'Movies',
array(
'labels' => array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'Movies'),
)
);现在编写此代码,以便在其中显示
<?php
$args = array( 'post_type' => 'Movies', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;?>
发布于 2014-08-28 03:44:27
创建CPT后,执行此操作以显示您的CPT的单个帖子:
single.php文件,并将其重命名为single-{post_type}.php (例如single-movie.php) 中的固定链接
您可以从this post获取更多详细信息
$args = array( ... 'post_type' => 'movie' )
有关更多详细信息,请查看this post。
https://stackoverflow.com/questions/12515421
复制相似问题