Custom Wordpress Template For Category - wordpress

I have two categories that need a special template. Each has one post and will display differently. So I read that if the category is named, for example, 'testing' and the template name is 'testing.php' then it should use that correct?
Why would it not? I keep previewing the post and it just redirects to the home page.

Naming the template testing.php won't work. You need to use either a slug or ID of your category, so either category-testing.php or category-ID.php if you know the ID of category (ie. you're not making a theme for release and your IDs are constant).

Category templates, which your version of WordPress has, can do it.

What version of WordPress are you running. WordPress 3.0 is new and will support what you want out of the box as you described.

Related

Wordpress: How can I use a category template if I remove the "/category/..." from the URL?

I want my URLs to not use "/category/..." to get to the category. So instead of
site.com/category/news
I want
site.com/news
I'm able to achieve this with a setting via the Yoast SEO plugin.
But I also have different presentations for certain categories, so I've created custom templates. The Wordpress template hierarchy will use a custom template for a category if it's named "category-[slug].php"
So, I have a category-news.php template that works as expected, but ONLY if the URL still contains "/category/..."
Is there a way to use my custom category template and still have "/category/..." removed from the URL?

Wordpress getting template for post category type to work

Hiall,
In my wordpress site I have a Category called “meetings”, and it’s slug is “meeting”, also its ID is 27.
I create a default post article and then select “Meeting” from the categories panel and then publish etc.
Reading here
http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display
If I create a template file called category-meetings.php or category-27.php then it should pick those files up and use them for a template layout for my selected Meeting category posts etc???
But for whatever reason I can not get it to do this.
I have also tried changing the permalinks settings from “post name” to custom structre with /%category%/%postname%/
but again no luck.
Am I missing something here?
Any help would be great!
I think you're trying to target a single post, whereas your template is targeting the category archive pages. For example, look at this diagram of the template hierarchy.
You could:
1) Create that post as a page and then create a template just for that page.
2) Create a custom post type and create a custom template for that custom post type.
The naming has to match your slug. I would change
category-meetings.php
to
category-meeting.php
And make sure the category-customname.php files are in the same directory as the default category.php file.
Addition/Revision
For a custom page for a single post -- find the post number, let's say 999, then create a single page with the past number appended to the file name in the same directory where the single.php file exists. This worked up to WP ver 3.2-ish. Unless it's been deprecated, it should still work.
single-999.php

Wordpress - Show parent category AND subcategory name in subcategory archive URL

I'm having some trouble with Wordpress category/subcategory archive URLs.
For example, I want to be able to display this archive: http://faroutmagazine.co.uk/wp/track-of-the-day while keeping its parent category in the URL, making it http://faroutmagazine.co.uk/wp/music/track-of-the-day
Previously, I was just getting a "This is embarrassing..." 404 message when accessing the /music/track-of-the-day URL (even though that's the one that was appearing in the View option under categories in the admin section of WP).
Now the View link in the admin area only shows me the /track-of-the-day URL, and this DOES display the category posts which is great, but I want it to include the parent category in the URL.
Is there anything I can do to the functions.php file or any plugins I can add to make this happen? Please bear in mind that there are multiple subcategory archives on this site, and they should all contain the parent category in the URL.
***UPDATE:
I actually have just set everything up a different way now using Pages and showing category archives on pages as it's taking up too much time. Thanks for your answer though. People telling me to use %category%/%postname% as the permalink structure are incorrect - yes, this works for the POST urls but not for the archive category of the subcategory which is the problem I was actually looking for help with. If anyone can provide an answer, it would be appreciated, but I am using this workaround now as this was taking up way too much time trying to figure out.
This happens because you chose category and subcategory from the right options tick boxes when editing the entry. Choose only the subcategory box in every entry and it will show the nested URL.
To make this happen you need to make some change in permalinks
go to Settings->Permalinks then select custom structure and use this syntax " /%category%/%postname%/ "in the field
Now save the settings and you can see the post url's using its category name in the permalink
Hope it helps :)
You should set hierarchical value to true when you are defining your taxonomy.
'rewrite' => array('slug' => 'mySlug', 'hierarchical' => true),
Then if you have a subcategory the url will be shown like this:
http://example.com/taxonomy/parentCategory/subCategory/
I found this sloution here:
https://wordpress.stackexchange.com/questions/155319/how-to-include-parent-terms-in-hierarchical-taxonomy-urls
Actually hierarchical subcategory archive permalinks are default in wordpress.
If you have a "pretty permalinks" structure selected in settings > permalinks, like /%postname% for example, then category and subcategory archive urls should default to something like:
yourdomain.com/category-base/category/sub-category/sub-sub-category
I had encountered a similar issue with a recent WP project, BUT I was using a plugin called WP No Base Permalink in order to get rid of my category and tag base slugs in my archive permalinks. When I deactivated the plugin, category hierarchy suddenly returned to my archive permalinks (luckily this project was still in development, otherwise, I would have had some major 404 problems).
I have not yet found/tested another plugin for eliminating category/tag base slugs that will also preserve hierarchy in sub/category archive urls, but it turns out that I do not need that functionality for my current project.
Instead I am using the base slugs blog-articles and blog-tags for the standard categories and tags in order to set the blog taxonomies apart from other taxonomies. Then I am using the plugin Types to create a custom post type and custom taxonomies for that post type. The Types plugin has an option in the advanced settings to set hierarchical taxonomy urls to true or false when creating a custom taxonomy.
Finally, I found a plugin called Remove Taxonomy Base Slug that effectively eliminates the default taxonomy term from the base slug of the taxonomy archive urls. And this, thankfully, does not interfere with the hierarchical sub/category urls, OR the base slugs for standard tags and categories.
So now, my blog categories/tags look like this:
yourdomain.com/blog-articles/category/sub-category/
or yourdomain.com/blog-tags/tag/
And my custom post type categories/tags look like this:
yourdomain.com/category/sub-category/ or yourdomain.com/tag/
Phew!
I hope this helps!
Setting Settings->Permalinks->Category base to '%category%' should give you what you want. According to WP doc:
Nested sub-categories appear as nested directories in the URI
See http://codex.wordpress.org/Using_Permalinks.
The Permalinks settings should be like /%category%/%postname%/ ..
If use custom permalinks settings as %postname% only, it will make your url in the form of .../category/subcategory.
You can use WordPress plugin to remove 'category' from url
http://wordpress.org/plugins/wp-no-category-base/
and then follow the instruction given by Maruti

Archive Page for Single Category in WordPress

I have two categories of posts on my site, for which I'd like to use the archives.php page.
I've already used it for REFERENCES.
I want to now use it for posts with a category of NEWS, but the customisations I've done for REFERENCES don't really work. Is there a way I can break to one archive page into two, or have a second archives.php page?
The Codex is very useful. That said:
http://codex.wordpress.org/Category_Templates
In the case of categories, the hierarchy is fairly simple. For instance, suppose the slug of the Category in question is news and the Category ID is 6. The Template Hierarchy specifies that WordPress will use the first Template file it finds in your current Theme's directory from the following list:
category-slug.php (Note: available with Version 2.9)
category-ID.php
category.php
archive.php
index.php
That is, if you do not have a category-slug.php (lets say category-news.php), WordPress will check for a category-ID.php (like category-6.php), and so on.

css formatting for a certain content

The thing (wordpress) is how can I make wordpress to format in a specific way (diferent from others) posts related to a certain category (it was in loop-single right?)
Does anyone have a nice link about this?
THX!
You'll want to use WordPress' Category Templates. For example if you have a category named news you can create template file named category-news.php (make sure you have permalinks enabled) or you can use the category ID. From there modify the contents of the category-news.php using CSS classes or IDs to display the styling you want for the category.

Resources