Custom Post Types
There are a few things with these custom post types. I asked this at the wrong place as well, but to also get the attention of people who are not interested in that plugin, another thread here.
My current custom post type situation is as follows: with the use of a plugin I created custom post types. Then I manually created new templates to display these custom post types and I created pages with these templates, because the plugin seems to not offer ‘indexes’ for the custom post types. This works fine enough for now. Now I for example have a custom post type “quotes” which displays at gangleri.nl/bookreviews/quotes, but when I tag a post with for example “dumezil” to group all the quotes of Georges Dumézil, this tag has the slug gangleri.nl/bookreviews/dumezil, while it should be gangleri.nl/bookreviews/quotes/dumezil.
Did I miss something or has something been missed?
Then there are some other things. The default single.php is used, the same sidebars as elsewhere, it is unclear if WP sees the posts there as posts or a page (since I use a page to display it), but I think the first, ‘recent posts’ will require some coding. That sort of things. All in development? But it seems plugins are released rapidly.
There is a plugin that says to fill some of these holes, but it doesn’t work, maybe because I already have another custom post type plugin installed and it does not seem to solve my most pressing problem of tagging. Any suggestions?
Hm, the custom taxononies seem to do the trick. I created the custom taxonomy “quotes” (amybe not a good idea since the custom post type is also quotes, but first I made “author” which is bad idea since that’s already a function in WP) as a test and assigned it to two quotes with the value “Evola” which nicely show up when I type gangleri.nl/bookreviews/quotes/evola (so not /tag/evola or quotes/quotes/evola) which is great, but I don’t know how to show that custom taxonomy with the quote (like a category or tag would). I tried:
<?php if( function_exists('the_quotes') ) the_quotes(__('Browse: '), ', ', '<br />'); ?>
in the custom page that I made to display the quotes.
But that’s of course a bit too simply thought.
I’m halfway, anybody knows the other half?
I cheered a bit too early. The custom taxonomy “quotes” in the custom post type “quotes” might not have been a too good idea. I am now experimenting with the custom taxonomy “from”, but things do not go as expected. I have a few “from”s, “evola”. “ellis-davidson” and “dumezil”. I have assigned a couple of quotes to them, expecting that they would show up at gangleri.nl/bookreviews/quotes/from/dumezil but that one results in a ‘page not found’ (not the WP page). quotes/from/evola only gives the first quote that I assigned that “from” to.
Two annoying problems remain. First, the pagination doesn’t work. The “previous” and “next” links seem to be correct (/quotes/page/2), but the index just refreshes and sometimes there’s a 404). I’ve tried previous and next page navigation which a funny result: the previous link goes to the previous page (which is not alltogether surprising), but the next link actually goes to the second quote in single view which on it’s turn gets single previous and next links that actually <emdo work. No working options as of now…
The other thing described above is still current: categorising, tagging and even custom taxonomies do not work. The latter does seem the best option, but somehow I can’t get it to work.
Just a thought. When the previous and next page links themselves are correct (which they are), but the first page just refreshes, could it be the query that I use that does not ‘understand’ that there are more posts?
<?php query_posts( 'post_type=quotes'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
Or something else in the template that I made perhaps?
Another thought. When I can’t get pagination correct, alternatelly I should also be able to make a page which only lists the last 100.000 titles (to make sure everything fits on one screen). The Codex suggests just that. It just gives a lonely piece of code though and, as a non-coder, I don’t know what to do with it. Is that something I can place in a template and assign to a page? How do I use it? I tried:
<div id="content"> <?php $loop = new WP_Query( array( 'post_type' => 'quotes', 'posts_per_page' => 10 ) ); while ( $loop->have_posts() ) : $loop->the_post(); the_title(); echo '<div class="entry-content">'; the_content(); echo '</div>'; endwhile; ?> <div class="navigation">
But that doesn’t work.
i found your rambling about custom post types quite interesting as i kind of went through a similar process in the attempt to figure out this very powerful beast!
i assume you have come across this?
i think it is a very simple and useful guide on what you can do with custom posts and taxonomies and from what you say i think you will find it useful too.
after playing around with the code and custom functions i cam across the custom post type UI plugin (the webdevstudios one) and this is doing most of the things for you!
Thanks for the tip. My first concern is the mailfunctioning pagination of the custom post type page. The article mostly speaks about the custom taxononies. I’ll look into that when problem one is solved.
I also use that plugin, but I’m starting to think I had better not… I put quite a lot of time in setting up the page that displays the custom post types and only then I found out that some thing do not function. When I deactivate the plugin, the custom post types are gone, but the plugin seems to conflict with similar plugins, so as of now, I have no idea what is the smartest path to walk. I think that when I can get the pagination to work I might no longer want to revert everything to what it was (what now are custom post types were just categories excluded from the index, so nicely archived, using the normal theme templates, etc.).
It’s a beast for sure. I have the idea that it was only half implemented…
well, i don’t want to mislead your train of thoughts, but if you look carefully at the default theme pages single.php is actually used for a single posts and the archive.php for listing a number of posts.
if you forget about custom posts and custom taxonomies for a moment, the codex is showing you how to create a ‘custom archive’ page which contains posts only with a specific category. see http://codex.wordpress.org/Function_Reference/query_posts
i’m not sure what you mean with ‘pagination’. with query_posts you have a reasonable flexibility already in the standard loop.
the same exact concepts apply when you use custom taxonomies as the way in which categories and tags work in the default installation are extended to them, the only difference is that you specifically say that instead of a standard post or page you want your custom ‘things’ and the associated taxonomy. does it make sense?
I think I’ve got all that. I use the plugin that you found too to make custom post types. Then I edited a template with a query to display only the custom post types and I added a page with that template. All good and well, but that page doesn’t ‘page’, meaning, when you want to go to “previous entries” that’s just the first page with another permalink. The link is correct (gangleri.nl/filmreviews/blog/page/2), the content isn’t. That’s why I figured it might be the query and later, why I decided to try an alternative, being, just a long list with titles.
ahah! now i get what you meant!
so try something like this (including all steps just in case):
<h3>Recent custom posts</h3> <ul> <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('showposts=5'.'&paged='.$paged); ?>
The first thing the code does is create a temporary variable to hold a reference to global variable $wp_query. The wp_query variable is set to null, and we instantiate a new WP_Query object.
Notice in the query above that we have these parameters:
The paged portion of the query is critical in order to have paging.
From there, we can now do our own query and begin our custom loop.
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul>
Now it’s time to create navigation links for paging:
<div class="navigation"> <div class="alignleft"><?php previous_posts_link('« Previous') ?></div> <div class="alignright"><?php next_posts_link('More »') ?></div> </div>
I guess I’m still unclear.
The idea was simple: to make a custom post type “blog” and to show them apart from the normal posts. I created the CPT and a page (a WP page) with a query that displays the CPTs. This works fine. There are a few problems with the page that I linked to, the major of which, is that you can’t browse to the “previous entries” (link at the bottom). That’s the thing that needs to be fixed first, forget all the rest that I said.
After that come some other things that I will look into then.
works fine, depends on the logic 🙂
where is the previous page supposed to go (literally)?
in the last example i gave you ‘previous’ and ‘next’ mean the dynamic list of things displayed in a particular post/page template, which is coming before/after the current sublist in the array of all available posts in the list you built up to the first one.
in your example it seems to me you have a single fixed page going to another fixed page: what is previous or next for this one?
i’m simply inferring here, but are you thinking to another page under the same ‘parent’? if that’s the case this has nothing to do with paging of fetched posts, it is a matter of constructing the right link as paging in this context works between items fetched in your array.
I’m sure it depends on my method, but it’s the only one I came up with so far. Like I said, I created a template (blog.php) with a query for my custom posts
<?php query_posts( 'post_type=blog'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
Then I created a page called “music blog” (that’s one of them) that I assigned that template to.
In your example, the paging worked perfectly, the thing is, I use the same in the template that I use. I gave a link to it before, here it is again. That template, by the way, is a slightly edited index.php. Your example made list dotted list of post titles not being the custom post types and as I yet fail to see the logic in PHP I cannot rebuild it to my needs (the posts displayed just as the ‘normal posts’ (in full, with metadata, comments, etc.) but then of course the custom post types).
I appreciate the effort. For some reason three years of WP has not brought me a single shred of insight in the workings of PHP. I can see what it is supposed to do and with some trial-and-error I am sometimes able steal some code that I need and use it, but 9 out of 10 times I simply don’t know where it goes and how to implement it. Take this
$loop = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => 10 ) ); while ( $loop->have_posts() ) : $loop->the_post(); the_title(); echo '<div class="entry-content">'; the_content(); echo '</div>'; endwhile;
that can never be right. It at least has to have a
?>but that’s about as far as I get.
A link of yours gave me an idea for a simple sollution:
I just add that to my query and set it to 1000, problem solved for now, right? Nope, I can’t manage to add it without breaking the template. I always tried to avoid having to code myself which usually works. This time somebody talked me into using a plugin that seemed to work perfectly at first, but after several of hours of work (moving posts from a certain category to custom post types and the building of the template, etc.) proved to do but half a job. I’d probably have needed less time when I just moved all the custom post types back to being just posts instead of trying to make this work, especially because this is only point one of several.
Oh well. I’m off for today. Thanks again and don’t spend too much time on trying to explain things to me, that’s a waste of your time too. This failing (to see the logic) makes me cranky anyway. Off to the gym, something that doesn’t require thinking.
- The topic ‘Custom Post Types’ is closed to new replies.