How to create fully reusable layout page template in wordpress? - wordpress

For all pages, Wordpress give us a default page template : page.php. That's clear and simple, by default all pages use this template. Then, Wordpress give us a page template system, and when we speak about template we think reusable so we think about page layout template.
For example : full-width, page-width, sidebar-left... You specifie the template to use for each page, it's ok.
But when you begin to work on a more complex web site, your content will not be a simple post (page type) inside a page template anymore. For a reason or another you have to use another feature of Wordpress : page-slug.php. Before, of course you can try to do shortcode for everything you develop, include specific plugins only for your complex page etc but ONE DAY, you will have no choice to use this page-slug.php.
Here comes the problem : the content is "more specific and complex" but you still need to use your layout template, and you can't... Of course, you hate duplicated code so you don't want to just "copy" your template inside.
If we really want a specific page, we use the page-slug.php without a page template and it do the job. Then...
Why Wordpress don't consider the page-slug.php as pure content when (and only when) a page template is specified ?
Am I missing something ?
Thanks

Related

Wordpress template assignment not working as expected

Whilst risking duplicating another post, I think this may be unique as other similar posts I've read haven't given me an answer that works for me. I have spent hours going through answers in other posts to no avail. I feel like what I've done should be working, but for some reason isn't.
I am new to Wordpress (but not development in general), and have set up a custom theme and page template (called index-gallery.php based on index.php and modified slightly to pull out my custom gallery posts). I have assigned that template using the page template dropdown on the right hand side of the page edit screen (using the remarked template name 'gallery page' that shows up fine in the list). So, you'd expect that to over-ride the standard hierarchy settings. However it isn't being applied and I'm seeing the index.php template being used. However, if I change the parent page of my 'gallery' page to be the home page it suddenly uses the 'index-gallery.php' template and the template works exactly as I'd expect. So I know it's not an issue with the template itself, as it works in that instance. I'm using 'what the file' plugin to see what templates are being used. I've tried re-assigning the slug in the page edit and re-setting permalinks etc, but that hasn't solved it.
Does anyone know what may be getting in the way of the template assignment when it's not parented to the home page? I don't really want it parented in that way.
This is all set up on my localhost running on xampp using Wordpress 4.9.7
You should rename your template files to something else (that doesn't begin with one of the standard WP template file names) - such as template-gallery.php
Oh, and you might find it better to base page templates on the page.php file anyway.

How to have single-slug behave like a normal page in WordPress?

I'm making a website in WordPress, and I'm using a plugin ACF PRO. I'm doing the entire site with flexible content, so the WordPress site is like a page builder.
Everything is fine, however, I came to a point where I need to have same functionality for single-[custom-post-type], so I can "Add row", header, footer etc... on it, but I can't figure out on how to do it.
I know that it's possible, because e.g if you look at this site here: https://rolleragency.co.uk/our-projects/
You can see that it works. I know they are using flexible content because I worked on that site and I did there what I wanted. I can't remember how to do that.
I think I had to use a Tempate Page? Or? I can't remember.
THe site is built entirely on flexible content, so everything there is modular and it's like a drag and drop, but how do I do that on single-slug?
You have to create a page template, yes.
So something like page-projects.php then in WordPress admin you would have a page called Projects.
The template you created should be automatically applied to this page. If it doesn't for some reason you can choose which template WP should use on the right side when editing a page.
Now, you can add whatever code you need to the page-projects.php. And also any fields you may need for that page you can set up in ACF by telling ACF to apply those fields to pages that use projects template.
This is how I would and did do it on several occasions :)

Easiest way to implement a temporary page to a Drupal 7 site

I'm a WordPress developer who's been tasked to create a temporary one-pager to a Drupal site. The client would like to have a simple front page with a logo and 4 external links until their new site is ready. Normally I'd just make a simple index.html page with some CSS and call it a day. But in this case they need some of the sub-pages from the Drupal site to continue to work.
Had it been a WordPress site, I would have just created a new template file and a new page inside WordPress, and made that the front page. But as I have zero experience with Drupal, I don't know if you can do the same thing here.
What is the easiest (quickest) way to make a simple splash-page as the front page, while having the rest of the drupal site continue to work? The splash-page should ignore all CSS and JS from the original theme — preferably have a completely independant section fromt the rest of the site.
In Drupal 7 you have few "levels" of templates. First you have "most outer" template html.tpl.php It contains html head and it is usually common for all pages.
Then inside that html.tpl.php you'll include page.tpl.php. That one should again contain some common page elements, as header and footer, but again, if your design requires that, you can have more than one page template.
Page template will include node template. In drupal you have 2 basic content (node) types but you can create many more of them. Basically for every different page layout you can create new content type (but there also are lot of different ways to achieve the same thing).
Basically you should create new content type called i.e. "splash" (machine name!). Add fields to it if they need to be back-end editable.
Then you should create new template file for your content type. Name matters, so you should call it node--splash.tpl.php . You can find and copy to your theme existing node.tpl.php and change it to your needs.
Keep in mind that when ever you add/remove new template file you have to clear the cache so drupal would scan theme directory, notice and start using new templates.
And if you need also different page template for you page you'll have to put some code into you tamplate.php file:
https://www.digett.com/insights/overriding-page-templates-content-type-drupal-7
Drupal template engine design an specific file name for override front page.
You can create the file html--front.tpl.php, and this will be used only for the front page without touch any other page. You can page here your custom HTML and reference css/js.
If the page you need share common styles with the rest of the site, I would recommend to instead override page--front.tpl.php which is basically the content of the page without the tags
For more information here is a link https://www.drupal.org/docs/7/theming/howto/customize-the-front-page-template

Request wordpress page and specify the page template

I have a website running Wordpress with a specific, custom theme and I would like to use some of the pages as an iframe within a different website.
The problem I am having is that I don't want to show the menu, header and footer, I want to use a different font and have the page load as quick as possible.
The best way to do this is to apply a different, bare page template to the page I want to embed as an iframe. However this will also affect the page when displayed on the website. There are plugins that will enable the content to be shown as json. This gets close to what I want to do but since it's an iframe I'd prefer to have some basic styling in there.
Is it possible to do the request for the iframe in a way a different page template is applied?
I've tried reading up about this but due to the sheer amount of articles explaining how the page template hierarchy works I've not been able to find anything explaining how to make the client influence this.
tl;dr can I do some sort of ?apply_template='page-bare.php' to enforce a different page template?
I think this might help you: Load post with a different template?
The way is:
Register new query variable
Redirect to a different template, when that query var is set
Create that template in the way you like it
get_template_part might also come in handy here.

Concrete 5 using Page Types and Page Templates from main Theme

it´s my first day with concrete5, i built a Sitemap with my Pages and added designs and Types. But the only used template is my default template, and i don´t know how to change it, cause i added page types and page templates as well.
help would be nice ;)
Before you start editing the template, make sure that you clear the cache [System & Setting -> Clear Cache]. As it will keep showing default.php until you do this. Are you using a custom template design? This may help: http://danmorgan.me/blog/concrete5-and-custom-themes/

Resources