Wordpress template assignment not working as expected - wordpress

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.

Related

Changing a template on a blog page - WordPress 3.5.1

I am using an older version of WordPress 3.5.1.
I know how to use different templates on different pages but the problem is I cant figure out how to set a different template for my blog page. When I open the page Blog in the Edit Mode I see a blank page, contrary to my other pages which display their content. Is it possible that this page is a redirected from somewhere else and how can I figure it out? Also when I change the template from Page Attribute it does not take effect. On any other page it works but this one. How can I figure out how to change the page template?
There's no built in selectable templating system for blog posts. Its based on the actual template files and their hierarchical structure.
http://codex.wordpress.org/Template_Hierarchy
Its probably your index.php or single.php that is throwing an error. I would go into the wp-config.php and find the line that says define('WP_DEBUG', false); and change that to true. Then reload the page and see if it spits out an error. A basic loop is only a few lines of php, so I would guess there's an error somewhere on the page.
As for the pages not changing when you change the template, its possible there is conditional code or something in the template itself. Are you saying it only changes the look of the page on some pages but not others?

How to create fully reusable layout page template in 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

Wordpress hierarchy breaking (3.1.2)

I've got a page in Wordpress that has a custom template assigned to it. It worked initially and without any notice it one day decided to default to index.php....
It won't go to its template_page.php or to page.php it always goes straight to index.php in my theme.
One extra odd thing i noticed is that when editing the page, it would not have the drop down underneath publish to select the custom template...never seen this before.
This is not the case for every other page i have on this build that uses a custom template. All other pages work just fine.
I have tried:
disabling all plugins / upgrading plugins.
changing and re-setting my permalinks.
deleting the page and re-creating it.
I've found that it will render the page occasionally but not always. I had solved it once and left it and it revert back to trying to use index.php to render the page after a few days.
I'm stumped, any thoughts?
Not sure why that would happen, but have you tried naming your custom template file page-yourpageslug.php or page-yourpageid.php. Wordpress should use that template by default without having to set it that way in the admin area.

wordpress page template not loading as front page

I have a page template set up as the front page but it's not loading for some reason. I've done this plenty of times in the past just fine.
I should be getting a body class of "portfolio-page-template" but rather I just get the regular "page-template".
I've tried resetting the permalinks, deleting/recreating the Portfolio page, changing back to the default theme and changing back, and still no dice.
Anybody know of a fix?
Need more info.
Did you save it as home.php did you override it in the settings? http://img.lajlev.dk/5a842c1e3dc470468c322af0fe79c004.png
Had a similar problem, and while it’s not an eloquent solution but when my working home page template started defaulting to my taxonomy.php template without reason, I tried all of the things you mention and then:
deleted the taxonomy template,
deleted the .htacces and refreshed the permalinks
selected and set the page-template-home.php again
noticed all was well
put my taxonomy template back and surprise - everything worked
very strange.
If this is not your issue, I can give you a few pointers on what to check for when setting up a custom page template, and what to check for if it fails.
Check the status of theme path or theme sittings

Post pages in Wordpress 2.9

I'm trying to use a posts page in Wordpress. For the uninitiated, this is a page (other than the home page) which features all your blog posts. You essentially turn on the static home page and point Wordpress at a custom index. Then you tell Wordpress to use another custom template as your "posts page"; thereafter, any post you make will wind up there.
My custom template for the 'Blog' page shows up as expected until I define it as the posts page. When I do, the template reverts to my custom index and I get no posts. When I undefine it as the posts page, it goes back to my template. What am I missing? I'm new to using this method, as it used to be done with a plugin prior to WP 2.9
So, I figured out the solution and wanted to share. Thanks for all your input, everyone.
The problem was with the name I chose for the template. I had called it "blog.php", which works fine when creating an ordinary page template. But when using a page as a posts page, Wordpress has some specific setup rules. The pertinent section of documentation, which I scoured the entire internet for using hours of my life I'll never get back, is hidden here:
Also, any Template assigned the Page will be ignored and the theme's index.php (or home.php if it exists) will control the display of the posts. (from here).
So, I named my template "home.php", since I wasn't using a home.php in this particular install, and I was off to the races. Anyway, thanks for the answers!
BTW, I think this may have been what Richard M was getting at.
Your problem might be in creating "templates" and the single post (single.php) You can create a template for any of your pages by putting this in the top of your page (after the first < ? php:
/**Template Name: ****templatenamehere**** #package WordPress * #subpackage Default_Theme */
...rest of code
This allows you to create a page called "posts" which references your new template. This way you can create a new template and then call it through a page. If this is confusing or you have tried this let me know and I will try to give you more details if you need. Thanks

Resources