WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Listing posts from a custom post type (3 posts)

  1. velocitykendal
    Member
    Posted 4 years ago #

    Hello there,

    This feels like a really dumb question yet I haven't managed to resolve it yet:

    I've created a custom post type, given it some custom taxonomies and all's good. I can view a post using utilising the single-******.php template and have set up a taxonomy.php template fine. But I can't seem to work out how to view a list of posts from the new post type.

    I have normal posts pointing to a page on the site and would like to keep those separate. So I want to point a menu item to a directory that will list the custom posts in the same way.

    example.com/customposttype/custompost/ - works fine, returns a post.

    example.com/customposttype/ - results in a 404 error.

    I don't know how to assign a template to the above directory?

    Can anyone help?

    TIA.

    Velocity.

  2. Roy
    Member
    Posted 4 years ago #

    Yes I know the problem. It is not too hard to solve, but every time a new thing appears. In my case the 'previous' and 'next' links don't work and I can't get the custom taxonomies to work. One thing at a time though :-)
    I have the idea that the custom post types have been implemented just half. There is a plugin that claims to fill the gaps:
    http://wordpress.org/extend/plugins/simple-custom-post-type-archives/
    It requires PHP5 and in my case, does not exactly do what it promises, but maybe you have more luck.

    If not, here's how to make an index for your custom post types:
    Take the index.php of your theme and replace the loop

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    by this:

    <?php
    $args = array(
    	'posts_per_page' => 100,
    	'post_type' => 'blog'
    );
    query_posts($args);
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

    my custom post type is called "blog" and I have 100 posts per page because the navigation does not work.

    Save the file as "blog.php" (or something) and upload it to the folder of your active theme.

    Then you go to WP, create a new page and assign the template "blog.php" to it and publish.

  3. velocitykendal
    Member
    Posted 4 years ago #

    Yeah thanks for that, that's (the latter) done the job. Luckily I don't need to use pagination in this instance.

    Cheers

    V.

Topic Closed

This topic has been closed to new replies.

About this Topic