WordPress.org

Ready to get started?Download WordPress

Forums

Category post template not working (21 posts)

  1. MaddTechWF
    Member
    Posted 10 months ago #

    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?

  2. Kakoma
    Member
    Posted 10 months ago #

    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

  3. MaddTechWF
    Member
    Posted 10 months ago #

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

  4. Kakoma
    Member
    Posted 10 months ago #

    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

  5. MaddTechWF
    Member
    Posted 10 months ago #

    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.

  6. Kakoma
    Member
    Posted 10 months ago #

    What URL are you checking?

  7. MaddTechWF
    Member
    Posted 10 months ago #

    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>.

    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.

  8. Kakoma
    Member
    Posted 10 months ago #

    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?]

  9. MaddTechWF
    Member
    Posted 10 months ago #

    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.

  10. Kakoma
    Member
    Posted 10 months ago #

    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?

  11. MaddTechWF
    Member
    Posted 10 months ago #

  12. Kakoma
    Member
    Posted 10 months ago #

    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

  13. MaddTechWF
    Member
    Posted 10 months ago #

    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>.

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

  14. Kakoma
    Member
    Posted 10 months ago #

    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

  15. MaddTechWF
    Member
    Posted 10 months ago #

    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.

  16. Kakoma
    Member
    Posted 10 months ago #

    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]

  17. MaddTechWF
    Member
    Posted 10 months ago #

    Well hell. I have two files: single-client.php and single-clients.php and neither are styling the individual client pages.

  18. Kakoma
    Member
    Posted 10 months ago #

    Let's try this:
    Deactivate all plugins
    Switch to the default theme, Twenty Thirteen
    Put the code I shared above in functions.php and then add both your files (single-client.php and single-clients.php) to the Twenty Thirteen theme directory
    Test

  19. MaddTechWF
    Member
    Posted 10 months ago #

    Okay, I switched over to the 2013 theme and deactivated all of my plugins. Still did not work.

  20. Kakoma
    Member
    Posted 10 months ago #

    Did you add the code to functions.php? And put the files in the Twenty Thirteen folder?

  21. MaddTechWF
    Member
    Posted 10 months ago #

    Yes I did.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.