Forums

2 archives on 1 theme? (16 posts)

  1. emilymcpherson
    Member
    Posted 10 months ago #

    Hi there, I hope that someone can help me (and that my question hasn't been answered a bunch before and I'm just cluttering up the forum).

    I inherited a site that has a bunch of templates modifying its post structure (adding address info at the bottom, stars for rating the posts etc, don't know why they didn't use plugins for this). These posts have been used as listings in a directory (hence the address section), but I want to also have a category of posts that is called Blog and works as a news blog.

    So far I've used a plugin (custom post template) to create a new post template for the news blog and made sure that all posts with that template are categorized as Blog (this category being linked to a blank page). This fix has stopped the extra info (address rating) from showing up on the blog posts, but I'm having difficulty setting the blog posts up with their own archive (so they're not categorized like the listings in the directory).

    What I've been trying to do is exclude the Blog category from the main archives template (which stores the listings in a specific way) and then create a simple archives template just for that category. It would be great if somebody could offer advice on the code I would need to do this. Also, if you think there's a better way to have two blogs going on my theme, I would love to hear it. Thanks!

    PS I chose the category method because I would like to eventually use a related content plugin to link the directory listings to relevant blog posts.

    Thanks again,
    Emily

  2. sixhours
    Member
    Posted 10 months ago #

    Set up two page templates--one for Blog, one for everything else. Then use query_posts to specify which categories to pull from/exclude.

    So if the Blog posts are in category ID 1, you'd use this before the Loop on the Blog page:

    <?php query_posts('cat=1'); ?>

    And this on the "everything else" page:

    <?php query_posts('cat=-1'); ?>

    The rest of the code you need can be found under the documentation for query_posts.

  3. Roy
    Member
    Posted 10 months ago #

    Emily, it looks like you mix up categories with 'custom post types'. Custom post types would probably be perfect for what you are trying to achieve, but it takes some work to get them the way you want. You can register a custom post type (or have a plugin do that for you) and you have to make extra templates to your theme (like you already did with the plugin that you mention), but also a template for the archive. Read more about it in the link that I gave you.

  4. sixhours
    Member
    Posted 10 months ago #

    Ahh, yes. My solution is only if you're using categories, not custom post types. :)

  5. emilymcpherson
    Member
    Posted 10 months ago #

    Thanks so much for your help, friends!!!

    I'm not actually using a custom post type, but when I make a news post I select blog post from the post edit screen (http://wordpress.org/extend/plugins/custom-post-template/)

    I also categorize it as blog...

    This is just one way I've tried. My goals are to preserve the blog directory listings the way they are (they're grouped into about 5 categories), but also have a simple news blog running alongside, archived chronologically. (The listings are archived by name, rating, # of comments).

    It sounds like making a custom post type for my new blog would work better than the category fix I've tried. I wonder, does the register post type go in the functions template? ((I actually tried to make a custom post type before, but I put the code in an archive plugin and fatal errored my site for a while;)

  6. sixhours
    Member
    Posted 10 months ago #

    Yes indeed, it goes in functions.php.

  7. emilymcpherson
    Member
    Posted 10 months ago #

    Thank you again!

    One thing that still worries me: if I set up a custom post type, might it still be affected by the templates that are currently adding features to the posts that are working as directory listing? Or perhaps it will be a completely separate thing?

    I suppose this is why I need to make extra templates (http://codex.wordpress.org/Post_Types#Single_template). I just want to make sure that I don't also need to exclude the new custom post type from the current templates...

  8. sixhours
    Member
    Posted 10 months ago #

    Any content in the custom post type will be treated separately from your regular Posts content, so no need to exclude anything on the default templates. :)

  9. Roy
    Member
    Posted 10 months ago #

    And as a tip, there's a plugin (or more) to change post types. That way you can change the post type from the posts in the blog category to the custom post types. The alternative is posting them all anew.

    The whole idea, the idea that you started with actually, it to create a different template for your custom post type. In the normal index.php you can have a lot of metas, such as author, date, category, tag, rating, whoknowswhat, in the other template (blog.php or whatever) you can add as many or as little as you want.

    And indeed, no more excluding ones all the blog posts are custom post 'typed'.

  10. emilymcpherson
    Member
    Posted 10 months ago #

    OK, I think have a lot that I can work with here...

    Roy, to your point, I actually have yet to move my news blog from Blogger into WP so the Blog category currently contains only test posts. My next adventure will be importing the Blogger posts and trying to make sure they become the right post type=)

    You guys are great. Thanks again for all your help!!

  11. Roy
    Member
    Posted 10 months ago #

    It could be that the WP importer has the option. If not, just import them and look for the plugin that I mentioned. I used it too, it works easy enough, but it's kind of tedious (one by one)...

  12. emilymcpherson
    Member
    Posted 10 months ago #

    So I've created a couple template files and added the below text to functions.php

    add_action( 'init', 'create_post_type' );
    function create_post_type() {
    register_post_type( 'CHIDS_news',
    array(
    'labels' => array(
    'name' => __( 'Blog Posts' ),
    'singular_name' => __( 'Blog Post' )
    ),
    'public' => true,
    'has_archive' => true,
    )
    );
    }

    I see Blog Posts on my side menu now and just used it to make a test post. However, when I try to view this post on my site I get a 404 error.

    Seems to me like the new post type cannot find the templates I made (archive-CHIDS_news.php and single-CHIDS_news.php). I wonder if you have any ideas how I might make the connection happen. Note that the archive file has only the default wordpress code in it (http://codex.wordpress.org/Creating_an_Archive_Index) and the single file is currently blank. Maybe this is the problem?

    As always your advice and guidance is sincerely appreciated.

    Thanks very much and all the best,
    Emily

  13. emilymcpherson
    Member
    Posted 10 months ago #

    `better code description...

    add_action( 'init', 'create_post_type' );
    function create_post_type() {
    	register_post_type( 'CHIDS_news',
    		array(
    			'labels' => array(
    				'name' => __( 'Blog Posts' ),
    				'singular_name' => __( 'Blog Post' )
    			),
    		'public' => true,
    		'has_archive' => true,
    		)
    	);
    }
  14. emilymcpherson
    Member
    Posted 10 months ago #

    Update: I've found by using a plugin, "Post Type Archives," I can get the custom post type to appear on my site (and have them be archived separately from the default type).

    However the new post type is still affected by the sidebar templates which modify the default type. I created a single template for the new type, but it doesn't seem to be being used...

    PS I actually made a new thread for this question, maybe I should take that down.

  15. Roy
    Member
    Posted 10 months ago #

    Hm, I don't know how to use a different single.php for custom post types. Perhaps you should work with if statements. Something like 'if normal post' this sidebar 'if post type is blog posts' that sidebar. I'm not enough of a coder to help you with that.

  16. emilymcpherson
    Member
    Posted 10 months ago #

    You know, I've actually come to think that I should focus on creating a custom post type for my directory listings and preserve the default post type for the blog posts. The sidebar templates were used back when you couldn't make custom post types, but now I think a custom type+plugins will provide the flexibility I need for the listings (e.g., star ratings, custom taxonomies, ability for users to edit).

    I will use the plugin you suggested to convert my 114 posts to the new type=) Then I will import my Blogger posts into the old type (with the templates removed).

    Now I've just got to convince my boss that this will all work!

Reply

You must log in to post.

About this Topic