我目前正在使用underscores.me框架来开发一个wordpress主题。 我会在主题中使用一些自定义帖子类型,随着时间的推移会添加更多,所以我想知道如何制作一个数组来获取各种模板文件。 目前在我的index.php上我使用以下 -
<?php if( array('movies','books') != get_post_type() ) { get_template_part( 'content', get_post_format() );} ?> <?php if( 'movies' == get_post_type() ) { get_template_part( 'content', 'movies' );} elseif( 'books' == get_post_type() ) { get_template_part( 'content', 'books' );} ?>我必须让content-movies.php文件的if参数最终被识别,我想要的是
a>使非自定义帖子类型的帖子只使用content.php
b>一个if数组,用于查找各种帖子类型,例如电影,书籍,社论
c>使每个自定义帖子类型查找其适当的内容 - [post type] .php AND single- [post type] .php
到目前为止,我已经成功实现了一个>但是对于b&c我遇到的问题是我的第二个帖子类型'books',我仍然使用content.php文件而不是content-books.php。 [编辑]要明确它导致索引中出现的书帖类型重复,一个使用content-books.php,另一个使用content.php
我还必须在functions.php文件中添加一些自定义代码以使CPT正常工作,并且如果怀疑它是原因,也可以显示它。
I'm currently using the underscores.me framework to develop a wordpress theme. I'll be using a handful of custom post types in the theme, with more being added as time progresses so am wondering how to make an array to get the various template files to be recognized. Currently on my index.php I am using the following -
<?php if( array('movies','books') != get_post_type() ) { get_template_part( 'content', get_post_format() );} ?> <?php if( 'movies' == get_post_type() ) { get_template_part( 'content', 'movies' );} elseif( 'books' == get_post_type() ) { get_template_part( 'content', 'books' );} ?>I had to make the if arguments for the content-movies.php file to be finally recognized, and what I'd like is
a> to make the non custom post type posts only use content.php
b> an if array to look for the various post types e.g. movies, books, editorials
c> to make each custom post type look for its appropriate content-[post type].php AND single-[post type].php
So far I've been succesful in achieving a> but for b & c the issue I'm having is that my second post type,'books', i still using the content.php file instead of content-books.php. [EDIT] to be clear it's causing a duplicate of book post types appearing in the index, one using content-books.php and the other using content.php
I also had to add some custom code to the functions.php files to get CPT's working, and can show that too if it's suspected to be the cause.
最满意答案
尝试
<?php if( in_array('movies','books') != get_post_type() ) { get_template_part( 'content', get_post_format() );} ?> <?php if( 'movies' == get_post_type() ) { get_template_part( 'content', 'movies' );} elseif( 'books' == get_post_type() ) { get_template_part( 'content', 'books' );} ?>Try
<?php if( in_array('movies','books') != get_post_type() ) { get_template_part( 'content', get_post_format() );} ?> <?php if( 'movies' == get_post_type() ) { get_template_part( 'content', 'movies' );} elseif( 'books' == get_post_type() ) { get_template_part( 'content', 'books' );} ?>更多推荐
发布评论