Wordpress taxonomy template exclude terms - wordpress

I have a custom Taxonomy. The lists of terms in the taxonomy will be dynamically created.
I have a custom template for Taxonomy as taxonomy-{custom-template}.php, but I do not want to use the same template for the terms page.
I will not be able to create template for terms upfront as taxonomy-{custom-template}-{term}.php as the terms are created dynamically.
Is there any option to exclude or have a generic template for the terms?

I'd use is_tax() in your taxonomy-{custom-template}.php to determine whether you are displaying the archive page or the terms page, and them include the relevant code in template parts.
Create 2 new template parts in your template parts folder - lets say its called partials
One is for your taxonomy archive page e.g. tax_archive_content.php.
Copy the archive-specific code from taxonomy-{custom-template}.php
into it.
The other is for your terms page - e.g. tax_terms_content.php. Put your new code for handling the terms in here.
Add the following to your taxonomy-{custom-template}.php
(This will replace the archive-specific code that you moved to tax_archive_content.php)
if (is_tax())
get_template_part('partial/tax_archive_content');
else
get_template_part('partial/tax_terms_content');
References for is_tax:
Codex: https://codex.wordpress.org/Function_Reference/is_tax
Developer.wordpress.com:
https://developer.wordpress.org/reference/functions/is_tax/

Related

Changing the "standard template" name of the single.php post template

I have a Wordpress website, now i want to change the post template name how it displays in the Wordpress CMS. Now it's saying "Standard template", i want to rename this to "News", just for usability reasons.
I can't find a way to do this. I know you can create new post templates by creating new files, but it always takes the single.php as standard template. I'm also using a child-theme, so i dont want to delete the single.php file, just rename the text: "Standard template".
Thanks in advance.
I tried creating a new post template file with a custom title. This doesnt solve problem, as the single.php file will still be the standard one (i dont want the user to have to change the template).
You can use another single.php for another post type for example if you have news registered as a post type you could have a single-news.php and that file then would server all the single views of postype = news. But from what i understand you would like to create a template appearing to the user with a different name. For that the best practice is to create a directory inside your child theme and name it page-teplates. Inside this directory you can create as many different templates you want and wordpress will recognize them but adding the following code at the top of each template. For the sake of the example lets say i want to create a contact page template. I will create a contact.php file inside the directory page-templates and have these lines of code inside.
<?php
/**
* Template Name: Contact
**/
get_header();
/* My templates Code/Design Here */
get_footer();
The possibilities are endless.
The code in this post will generate a dropdown box similar to the one that you see in pages.
All it requires is a little editing of your child themes functions.php file .
In most cases, you just need to copy your single.php file to a new file name in your child theme and edit the functions.php file in your child theme. Name your templates as seen in the code Dimitrios posted.
consider using the premium elementor page builder to create custom post templates that you can apply at will.
Try a plugin like Post Custom Templates Lite

Custom template file for displaying the inner blog contents

I am trying to create a custom layout for my blog listing and blog content display pages.
The following url will display all the latest blogs based on the conditions that I have set.
http://fqdn/general-blog
When I click on the 'Read more' button corresponding to a button, it will display the full blog contents in another page.
Sample format : http://fqdn/general-blog/tourist-details
I am able to modify the layout of the page corresponding to blog listing. For this, I have created a custom tpl file : page--general-blog.tpl.php.
What I want is to create a new template file for displaying the contents of individual blogs.
The individual blog content display page is not entering - page--general-blog.tpl.php file. It's always using the template - page.tpl.php.
I tried creating separate tpl files like :
page--general-blog--%.tpl.php
But, the changes in this template is not getting effect in the individual blog content display page.
How should I move forward. Has someone had any similar situations?
If your content type has name general-blog,you should name single blog entry template as node--general-blog.tpl.php. See
Theming nodes by content type for details.
If you need to theme whole page template depending on node type, you should add following code in your template.php:
function YOURTHEME_preprocess_page(&$variables) {
if (!empty($variables['node']) && !empty($variables['node']->type)) {
$variables['theme_hook_suggestions'][] = 'page__node__' . $variables['node']->type;
}
}
And then use page--node--general-blog.tpl.php file (see Page templates depending on node type for details).
Don't forget to clear the theme registry after creating new template file.

Specialized template for subpages?

If I have a page named 'events' (of which the specialized template will be named 'page-events.php'), is there any way to have a specialized template of a subpage 'events/event-sub-page'?
I can't seem to find how to do it in the documentation here: codex.wordpress.org/Page_Templates.
You would just create a new template called events-subpage.php and build it accordingly. Then when making your page in wordpress, select the template events-subpage.
You can just create the "event-sub-page" page in WordPress, set its parent to the "events" page, and make your custom template file "page-event-sub-page.php" (no need to specify the "events" part in the actual php filename)
Or in my case I wanted "../login" for a specialized login form and "../login/recovery" for password recovery. The template page is simply "page-recovery.php"

custom post type template

I have a custom post type "recipes". I created it using the custom post type UI plug in.
the name is ic_recipes, the label is Recipes and the rewrite slug is recipes
the url is formed as mysite.com/recipes/lentil-soup/
Here is the question...
I wanted to create the template file for this custom posts types to use..
but no matter what i tried, wordpress ended up using the single.php.
I've supplied the following files to the twentyten theme folder;
recipes.php
ic_recipes.php
archive-recipes.php
and finally archive-ic_recipes.php
none kicked in. single.php was the one every single time.
I checked the codex. codex has the the following to say ( I copy/pasted for you at the bottom of this question) about the the template naming!
Please tell me what is it that I'm missing..
http://codex.wordpress.org/Template_Hierarchy#Custom_Post_Types_display
Custom Post Types display
archive-{post_type}.php - If the post type were product, WordPress would look for archive-product.php.
archive.php
index.php
archive-xxx.php is for archives. You want to use single-xxx.php as an alternate to single.php.

Wordpress - How can I create my own template outside of the expected hierarchy of templates and feed a query to it?

BACKGROUND
I have used WordPress custom post types to create a newsletter section for my website. Newsletters consist of Articles (dm_article), which are grouped by the Issues taxonomy (dm_issues).
1) I have created an index of all of my newsletter Articles. I am using a template called taxonomy-dm_issues.php to loop within a selected Issue and display each Article's title, excerpt and a link to the full content, which is managed by single-dm_article.php. This is working great.
2) I would also like to create second taxonomy-based template for Issues. This is going to act as a print-friendly option: "print entire newsletter". I would like the template to loop through and display each Article title, excerpt, and long description. Some of the look and feel will also be different.
For #2, let's assume I've created a template called print-dm_issues.php. It currently looks identical to taxonomy-dm_issues.php, except it has the additional long description data for each Article and contains some different styling.
I want to setup this "print friendly" option without making the WordPress admin have to jump through any hoops when Issues and Articles are created. I also do not want to have to create a new template each time a new Issue is created.
CORE QUESTION:
What I am asking for may boil down to this: How can I create my own WordPress template outside of the expected hierarchy of templates and feed a query to it? Do note I am using the "month and name" common permalink structure, so I'll have to muck with my htaccess.
ALTERNATIVES:
1) My fallback is to have taxonomy-dm_issues.php contain the information for both variations and use style to handle the different view states. I know how to do this. But, I'd rather not do this for sake of load times.
2) Using Ajax to fetch all of the Article long descriptions (the_content()) with a single click is an option, but I don't know how.
3) ???
With or without clean URLs, you can pass variables based on your taxonomies through the links query string if you want to only return a single taxonomy term and style the page differently depending on the term.
$taxonomyTerm = $_GET['dm_issues'];
$args=array(
'post_type' => 'dm_article',
'dm_issues' => $taxonomyTerm,
'post_status' => 'publish',
);
There is reference to this int he Wordpress 'query_posts' documentation by passing variable into your query parameters: http://codex.wordpress.org/Function_Reference/query_posts#Example_4
For instance in the link below, the title is generated based on the sting in the URL.
http://lph.biz/areas-we-serve/service-region/?region=Conestoga
You can set up a parameter that will return a default value if the page is reached without the variable being defined. See below:
if (empty($taxonomyTerm)) {
$taxonomyTerm = 'Default Value';
}
You can create a separate page template. Define the template name at the top of your PHP document:
<?php
/*
Template Name: Printed Page Template
*/
Place your custom query, including all of the content that you need output in this page template... In your WP admin, create a new blank page and assign your new 'Printed Page Template' template to this page. Save it and view the page.

Resources