Support » Fixing WordPress » Category post template not working

  • I have read the article on category templates and I can’t get mine to work. I have made a template page called category-clients.php and single.php and clients.php and nothing seems to work.

    Can anyone tell me why it’s not?

Viewing 15 replies - 1 through 15 (of 20 total)
  • Do you have a category named ‘clients’? (single.php isn’t for categories so it won’t work)
    clients.php won’t work either

    From the category template heirarchy, WordPress will use the first Template file it finds in your current Theme’s directory from the following list:: (in order of ‘priority’
    http://codex.wordpress.org/Category_Templates

    category-slug.php
    category-ID.php
    category.php
    archive.php
    index.php

    If your category slug is ‘clients’, category-slug.php will work. Confirm what your slug is and change your file name accordingly

    I’ve created a page template called category-client.php and it will not pull the layout at all.

    Two things:
    1. Where are you checking? category-client.php is for the Archives page of the category with the slug ‘client’. This page can be found here:
    http://{yourhost}/?cat=x
    Where x is the category ID
    2. What is the slug of your category? Is it ‘client’?

    Confirm these two things. It’ll work

    X is 4 and category slug is client. I have two pages created category-4.php and category-client.php. Neither render my page layout. They are all defaulting to my index.php page.

    What URL are you checking?

    http://localhost/client/client-name

    Could this be the issue? I have a page called clients on my site which is a list of all my clients (http://localhost/clients). Then when I click on a client’s name it takes me to http://localhost/client/<client-name&gt;.

    I want a page that has a list of all my clients and then be able to click on a client and have a custom-page of how the client’s data is layed out.

    Ahhhh. Eureka. I ought to have asked the right question from the get-go. That’s where the issue is. URLs.

    category-4.php kicks in on http://localhost/client/?cat=4 [Assuming your WordPress install is in the ‘client’ folder]

    What is your site name?

    [Have you considered custom post types?]

    I don’t have anything up live yet. Everything is running using lamp right now. I’m new to modifying themes. Any help/suggestions would be much appreciated.

    That’s fine. http://localhost implied that you are working locally.
    I meant what’s your site’s folder name in your www directory?
    Alternatively, what’s the URL of your homepage?

    Ok so the template you created, category-4.php will appear here:
    http://localhost/virtualassistant/?cat=4

    Suggestion one: [we’ll stop when we find something that works for you]
    1. Create category ‘clients’ (Or ‘client’, you seem to already have one called this)
    2. Change your permalink structure (Settings > Permalinks) to custom and use this
    /%category%/%postname%/
    3. Create posts, and name them using the client names
    4. All your clients will be displayed here: http://localhost/virtualassistant/category/client
    If ‘client’ is your category name

    Suggestion two involves custom post types. It involves a bit of development

    Okay, I think I’m going to want to go the hard way. I’m a little A.D.D and I want my URL to look a specific way. I would really like for my list of clients to stay on the existing http://localhost/virtualassistant/clients page and then each individual client page be on like the following http://localhost/virtualassistant/clients/<client-name&gt;.

    I just don’t like having the word category in my url.

    That’s perfectly ok. Then let’s use this: [Custom post types]
    To the functions.php file in your theme, add this:

    add_action( 'init', 'create_post_type' );
    function create_post_type() {
    	register_post_type( 'clients',
    		array(
    			'labels' => array(
    				'name' => __( 'Clients' ),
    				'singular_name' => __( 'Client' )
    			),
    		'public' => true,
    		'has_archive' => true,
    		)
    	);
    }

    It’ll work. In the event that you want to know a bit more about what’s going on, check this out:
    http://codex.wordpress.org/Post_Types#Custom_Post_Types

    Okay. I’ve added the code that you provided and I have a page called “Clients” with a loop that shows a list of my clients. When I click on a specific client, it takes me to http://localhost/virtualassistant/client/<client-name&gt; but still not taking my template. I read in that article to make a page called single-<cat-name>.php as my template. I did that but it’s not using it.

    You ought to be looking at http://codex.wordpress.org/Post_Types#Custom_Post_Type_Templates

    single-{post_type}.php

    Your file should be single-client.php for it to be used [or single-clients.php, depending on what you called the post type]

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Category post template not working’ is closed to new replies.