Wordpress ignoring page template from drop down - wordpress

I am struggling with something that appears to be easy, page templates. I have read plently posts on this, people seem to forget to put the comment at the top of the page and can't get it to show up in the drop down menu on pages. I can do this, my problem is the next stage.
I have written the most basic template (custom-page.php):
<?php
/*
Template Name: Test template
*/
?>
<?php get_header(); ?>
<h1>Teams!</h1>
<?php get_footer(); ?>
It shows up and I can select it on the new page sidebar. However when I visit that new page it seems to have defaulted the archive page using the content template include.
Thanks in advance.

If you put the following in your footer, you should be able to grok some further information about how your template is being selected (and know exactly what might be happening).
<?php global $template;
echo(basename($template)); ?>
Then look for the template name in your footer. It's possible (like #adomnom said) that you have a slug conflict. There are a handful of other strange scenarios that could be caused by plugins, custom functions, or other factors as well.

By the sounds of things, it could be conflicting with another template.
For example, if your page has the slug 'category' and is set to use the custom template 'custom-template.php', it would conflict with (and be overridden by) category.php, which is the default template for showing posts for a specific category.
I recommend changing the slug to see if that's the problem.

Related

Archive Page Template returns posts instead of page content on Polylang second language

I have an issue with Polylang and custom archive page template. On my main language my archive page shows page content but on second language it starts looping trough posts.
<?php
/* Template Name: Archive Page Custom */
get_header();
while (have_posts()) : the_post();
the_content();
endwhile;
?>
<?php
get_footer(); ?>
What causes this?
Cheers
I have solved this. It turns out that under Polylang settings I had to uncheck my custom taxonomies because it completely breaks the site.
EDIT: Never mind this doesn't work because as I turn it off it shows posts from all languages on my archive first page. So it still has to be turned off to filter posts between languages.
So the issue remains. Archive page with default language loads content in from the page and secondary language shows posts for some reason instead of content.
EDIT: It was a conflict with archive-portfolio.php template and also I had custom post type slug named same as my secondary translation so the page broke. I had to rename my archive-portfolio.php template to portfoliotemplate.php and it works now.

Wordpress: Pages work, Posts don't

First of all, I'm totally new to WordPress so please be patient :)
Anyway, I have created a custom theme with a bunch of pages, a menu and a startpage (index.php), and everything is working fine. I have also created a few posts and those are not working at all. I have created a small loop that display the 5 latest posts on the startpage as links with date, and they show up as intended, but if I click on one of the links the startpage just reloads. As the page has reloaded it displays the correct permalink in the browser address bar, but I'm still stuck on the startpage. Same if I try to preview my posts from WP-admin, it just display my start page.
I have no idea what I'm doing wrong here and I'm no php coder. This is the code I have in my page.php file, maybe there is something wrong with it?
<?php get_header(); ?>
<div class="content">
<?php while ( have_posts() ) : the_post(); the_content(); endwhile; // THE LOOP ?>
</div>
<?php get_footer(); ?>
there is a difference between posts and pages. Try to put this code into a file called index.php so it will work for posts too.
If wordpress cant find a page.php (this is for pages) or single.php (this is for posts) it will look into the index.php as a fallback.
those are the files - enjoy :)
1. style.css: your page styling goes in here.
2. index.php: acts as fallback if the specific php files are not found.
3. single.php: single posts template
4. page.php: single page styling goes here
5. archive.php: acts as archives template (by month, author,...)
6. searchform.php: style and configure your searchform here
... there are many more. here is a cheat sheet with page types / theme structure .If you need further information google for types followed by tutorial
example: wordpress single.php tutorial
all the best
fab

wordpress custom pre-fixed templates

I want to create a page template that has a pre-fixed css. Lets say I name it page-sevencol.php then I know that the content will have a fixed width and a specific style and so on. My pages have different layouts thats why I need to create these kind of templates.
Is it possible? if so how? Ive looked in the wp codex and it does not seem to have the answer. Please take a minute to help me.
Thank you!
you seem to need just a limited set of templates. The question is: do you want to apply them automatically? Basically, there are two techniques to apply a template to a page (or post or custom post, etc.) in WordPress.
First method: using the template naming convention to get the template automatically applied to a page (or post) with the same name.
In this case, you create a page page-mynewpage.php and this template will automatically get applied to your page named /mynewpage/.
Second method: you create a template by creating a page (let's say : template1.php) and declaring it as a template with a comment at the top of the page:
/**
* Template Name: Template1
*
*/
This template will now be selectable inside the admin of WordPress to be applied to any page:
So if A) you only need a limited set of templates & B) are ok to select them on a per-page basis in the admin, this is your solution. You would just need to create as many pages as you need templates, not forgetting to include the comments that declare them as templates and using a different name each time.
If you need your templates to be applied dynamically, then we need more info about the logic to use for select each template...
EDIT : That is it, Abel (just read your comment). Your page is mainly generated with 4 elements: header.php, sidebar.php, footer.php and another page to produce the content, but this page is different depending on where you are in the site. If you are on a page, it will be, by default, page.php. If you are reading a post, WordPress will by default use single.php.
To apply all your different templates, just go and open page.php in your theme folder. Save it under another name, like page-template7cols.php. Insert a comment like I just explained above, so this template will show in your admin next time you create a new page. Adapt it the way you want (changing the HTML / PHP and therefore adapting the way the content of the page will be displayed). Do the same for your other 9 templates.
Then, everytime you create a new page, just start by selecting the proper template in your dropdown (see previous screen capture). And whenever you will make a change to page-template7cols.php, for example, the changes will be reflected on all pages for which you have selected this template.
/**
Template Name: Template1
*/
<?php get_header(); ?>
<div class="content-wrap sevencol clearfix">
<div class="row clearfix">
<div class="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Blog page with theme completely different from the main theme?

I have been trying to make my website on Wordpress. I am using Brave Zeenat as my primary and Grido as my blog theme.
I have read many tutorials in places, which discuss how to apply a customized flavour of the main theme on a static page, e.g. Blog. However, the main theme I am using does not appeal to me as a blog theme at all, so I wanted to do something entirely different, so I have tried two methods.
First, I tried to just create a page named Blog and force it to take a theme of my choice using the Page Theme plugin. That worked instantly, but the blog page is empty and would not accept articles of certain categories by default like this.
Second, I tried to not use any plugin at all, and use a custom PHP file instead, which sets some loops and calls a theme. This file blog.php had to be in the main theme directory, otherwise it would not be applicable as a template from the page settings in Wordpress dash.
So I put it with my main theme, but call to load the other theme, like this:
<?php
/*
Template Name: Blog
*/
$paged = get_query_var('paged');
query_posts('cat=0&paged='.$paged);
global $more;
$more = 0;
load_template(WP_CONTENT_DIR . '/themes/grido_v1.0.1/index.php');
?>
Eventually I only want to see category no.9, but for now, I left it as 0, which should display all categories. But when I run this with Page Theme plugin disabled, I get this error: Fatal error: Call to undefined function themify_get() in /var/sites/v/visualdeceptions.info/public_html/wp-content/themes/grido_v1.0.1/index.php on line 10.
Now, although this is a themify error, I am sure if I try to use other premium themes as well, I will encounter very similar errors, because I have only set a custom php file, and no style, header, footer, etc. But I am not sure how to do it.
Try to add getheader() and getfooter() in the code
<?php
/*
Template Name: Blog
*/
get_header(); //HERE
$paged = get_query_var('paged');
query_posts('cat=0&paged='.$paged);
global $more;
$more = 0;
load_template(WP_CONTENT_DIR . '/themes/grido_v1.0.1/index.php');
get_footer(); //HERE
?>

How do I get the WordPress sidebar to show up on a post's detail page?

My example is here
I am customizing the default template, but something isn't placed right. Can't figure it out.
By the way, I am asking this here and not at WordPress because frankly, their forums are horrible as far as response times go. Stackoverflow has always done me good :)
Without seeing the php code it'll be hard to know why. Do you have a seprate template for single post ie singlepost.php? If so, make sure you're include sidebar.php into that.
Looks like single.php in the default theme doesn't pull in the sidebar by default. You'll need to add <?php get_sidebar(); ?> right before <?php get_footer(); ?> in single.php or just delete the single.php and wordpress will use index.php instead which has the sidebar.

Resources