Multiple thumbnails in WordPress based on page template? - wordpress

Is there a way to add multiple thumbnails in a page based on page template or page ID
instead of post type (post, page)?

You can add a conditional statement to test for a specific page id:
if(is_page('<your page id>')){
// Do your thing
}
Similarly, you can test for a specific page template like so:
if(is_page_template('<page template file name>']){
// Go on wit' you bad self
}
Make sure that when you use is_page_template() that you feed it the file name of the template, e.g., is_page_template('two-columns.php'), as opposed to the name of the template, e.g., is_page_template('Two Columns').

Related

Drupal: page specific theming without node-id

I am adding a page with a node-id and earlier I was using "page--node--node-id.tpl.php" template to customize the node/page. However, I accidentally deleted that node, and now I am unable to create that node with particular nid node. I want to know how to customize the specific page as each page his unique title.
Use page--node.tpl.php for all the nodes instead of each template otherwise use
node--[node-type].tpl.php for specifc node content type template
There is another smart step to create content type template with your own specific name by following below code
function themeName_preprocess_page(&$vars, $hook) {
if (isset($vars['node'])) {
$vars['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $vars['node']->type);
}
}
In above case If node content type is "article" then the template suggestion will be "page--article.tpl.php".
Create template file page--nodetype.tpl.php in your theme directory.

Custom post type: creating a page template with the same slug

I'm currently working on a custom post type and want to be able to edit the archive page from Wordpress with a page template. So I created the CPT called 'cars' and created a page template with template name: 'Cars overview'. Next i create a page inside WordPress and choose the template page 'Cars overview' and gave it the URL: mywebsite.com/cars/
Now the problem is that the slug 'mywebsite.com/cars/' is already in use by the custom post type itself causing the page to load the custom post type loop instead of the page template loop. So I can't edit the title, content etc inside WordPress. I could change the url of the page, but i want to be able to control the overview page in WordPress.
Long story short: How can I create a page template that is using the same URL as the custom post type archive page?
Thanks in advance!
One simple solution, simply disable the archive where you create your custom post type:
register_post_type("cars", array("has_archive" => false));
Another approach rather then disabling the archiving and adding another page to show the cars. Changing the archive template used by your theme might be a better option.
First step is to find the template currently in use by your theme, copy it to your plugin file and you can change the template file to whatever you like. You can find more information about it here.
The only thing you need to do is point WordPress to the right direction:
add_filter("archive_template", "archive_template");
function archive_template($archive_template) {
global $post;
if ($post->post_type == "cars")
{
$archive_template = "path/to/your/template.php";
}
return $archive_template;
}
Disabling the archive and creating one manually seems a bit strange to me. And I always replace the archive page and sometimes single page from our theme (usually the7).

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"

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