$10
3.0-alpha, custom post type
http://wpengineer.com/impressions-of-custom-post-type/
got good explaning about backend support of custom post types.
but.. what about in templates?
function post_type_movies() {
register_post_type(
'movies',
array(
'label' => __('Movies'),
'public' => true,
'show_ui' => true,
'supports' => array(
'post-thumbnails',
'excerpts',
'trackbacks',
'custom-fields',
'comments',
'revisions')
)
);
register_taxonomy( 'actor', 'movies', array( 'hierarchical' => true, 'label' => __('Actor') ) );
register_taxonomy( 'production', 'movies',
array(
'hierarchical' => false,
'label' => __('Production'),
'query_var' => 'production',
'rewrite' => array('slug' => 'production' )
)
);
}
add_action('init', 'post_type_movies');for example for this movies post type and taxonomies.. what codes/files i need to place to use this properly? i mean for displaying in site.
Let me explain step by step;
svn co http://core.svn.wordpress.org/trunk/ .
We got trunk version. Installed wordpress. 3.0 alpha
Using default twentyten theme and using above code for creating custom post type. Now we have movies panel in admin section.
BUT i cant see movies link as normal. In this position, whats best way? Creating a page and using custom loops?
Ünsal Korkmaz | 02/28/10 at 3:55pm
| Edit
(5) Possible Answers Submitted...
-

Last edited:
03/25/10
1:59pmBrian Richards says:Are you asking where you should place the example code? If so, drop it in the functions.php file for your theme.
If you're asking how to retrieve/display these custom post types, you'd just need to use a custom loop that pulls the custom type, rather than posts.Previous versions of this answer: 02/28/10 at 3:59pm
- 02/28/10 4:01pm
Ünsal Korkmaz says:i mean wpquery, template files,custom loops etc for displaying custom post types.
- 02/28/10 4:03pm
Ünsal Korkmaz says:yeah.. i need code samples.
how display movies post types, actor taxonomies etc.. - 02/28/10 4:10pm
Brian Richards says:add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() )
$query->set( 'post_type', array( 'post', 'page', 'album', 'movie', 'quote', 'attachment' ) );
return $query;
}
It's that simple. Put in the array whatever custom post type you want to display. For even more details, Justin Tadlock has a more comprehensive article.
- 02/28/10 4:16pm
Brian Richards says:For displaying custom taxonimies you can use:
<?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ', '' ); ?>
Just replace people with the taxonomy you wish to display. Put this in the theme wherever you wan't the post's taxonomies to appear (within your loop)
This is another exceprt from one of Justin's articles - 02/28/10 4:26pm
Ünsal Korkmaz says:this is well known "home page" solution. thanks for linking again :) but its not explaning what i am looking for.
movies custom post type.. but movies.php will work in template?
example.com/movies not working.. what about pagination? - 02/28/10 4:30pm
Brian Richards says:Sorry, my first example for returning post types was applied very specifically for including them in the loop on your homepage. To include custom post types in their own separate loop anywhere else, you can use the query_posts() function.
For example:
<?php
// Display custom post type 'movies' using query_posts
query_posts('post_type=movies');
// the Loop
if (have_posts()) : while (have_posts()) : the_post(); ?>
...whatever you want to do inside the loop...
<?php endwhile; endif; ?> - 02/28/10 4:38pm
Brian Richards says:Pagination is a little tricky, but is also possible.
Here's the skinny on pagination using query_posts
The trick is making sure you store a paged variable to insert in the string, I use this:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
Then within the query I just add&paged='.$paged
So, combining this with the above example would give you:
<?php
//Setting Paged value
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// Display custom post type 'movies' using query_posts
query_posts('post_type=movies&paged='.$paged);
// the Loop
if (have_posts()) : while (have_posts()) : the_post(); ?>
...whatever you want to do inside the loop...
<?php endwhile; endif; ?>
Of couse, you would also need to include you paging navigation - 02/28/10 5:44pm
Ünsal Korkmaz says:so which file will it put those codes?
movies.php? like page.php etc.. - 02/28/10 6:34pm
Brian Richards says:Personally, I would make a custom page template. So you can name the file whatever you like, so long as you include the php comment at the beginning that identifies it as a custom page.
Then in the backend you can just create a new page and select your custom template. - 03/01/10 12:03pm
Ünsal Korkmaz says:you know this is not a solution right?
- 02/28/10 4:01pm
-

Last edited:
03/25/10
1:59pmFrank Bültge says:Im the aouthor of the post on wpengineer and you must read the comments on this post; Brian has the right and easy way, use the post tpy on query and after this the loop.
<?php
// Display custom post type 'movies' using query_posts
query_posts('post_type=movies');
// the Loop
if (have_posts()) : while (have_posts()) : the_post(); ?>
...whatever you want to do inside the loop...
<?php endwhile; endif; ?>- 03/01/10 12:29pm
Ünsal Korkmaz says:ok basically creating loop is only solution ofc. Problem is.. which file? page.php? loop.php? or creating a movies.php?
i will have 4-5 different custom type lets say. I want 4-5 different loop so. - 03/01/10 1:31pm
Frank Bültge says:This an other problem, is in dependence of your theme, the design, and view of the frontend; the page.php is only for pages, not posts. Yo uadd a custom post type and you must ask for this on the loop, example single.php, index.php and archive.php. You can allways work with many loops or one loop and filter this to the post-types, better for perfomance.
- 03/01/10 3:50pm
Ünsal Korkmaz says:Using default twentyten theme. So i was expecting example of "how to" on a default theme. I will handle other themes when i can understand way :-/
- 03/01/10 12:29pm
-

Last edited:
03/02/10
2:02pmMichael Fields says:Ünsal Korkmaz,
You should see this trac ticket. I have not tested any of these new template types yet, but it seems to be exactly what you are looking for:
http://core.trac.wordpress.org/ticket/12105
This appears to be the new Template Hierarchy for single views for custom content types in 3.0:
The new approach:
* singular-post_type-slug.php
* singular-post_type-id.php
* singular-post_type.php
* singular.php
* single.php (for backwards compatibility) -

Last edited:
03/02/10
11:33pmSony Murdianto says:function apply_filters($tag, $string)
{
global $test_filter;
if (!isset($test_filter[$tag])) return $string;
uksort($test_filter[$tag], "strnatcasecmp");
foreach ($test_filter[$tag] as $priority => $functions)
{
if (is_null($functions)) continue;
foreach($functions as $function)
{
$string = call_user_func_array($function, array($string));
}
}
return $string;
} -

Last edited:
03/03/10
11:27amHardian Nazief says:lets say you want to create a custom taxonomies of writer
to roll up the list of your writer use this code
<?php wp_tag_cloud( array( 'taxonomy' => 'writer') ); ?>
You put the custom loop here just like tag.php page but for a specific taxonomy
taxonomy-writer.php
a more comprehensive structure is
taxonomy.php /* All taxonomies */
taxonomy-tax_name.php /* Specific taxonomy */
taxonomy-tax_name-slug.php /* Specific term within a specific taxonomy */
you should check out justin tadlock article about movies database
Previous versions of this answer: 03/03/10 at 11:26am | 03/03/10 at 11:27am
This question has expired.
Current status of this question: Completed





