Wordpress using wrong template - php

I have installed Wordpress multisite (5.5.1) and created some custom post types. I have also created some custom templates.
Custom post type: "illustration"
Template file: illustration.php
The template file is empty apart from the name and an echo showing the template name
Theme Name: ae-2020
Template Name: illustration
Template Post Type: illustration
*
The template for displaying illustration pages
*
Version: 1.0
Description:
*/
The template name shows up in the page attributes dropdown. However when I view the post the index template is used. If I go to posts and view the "Hello World" post it uses my single.php template as expected.
What am I doing wrong?
Help appreciated.
David

Maybe this can be helpful, this shows what prefixes and names to uses in wordpress hierarchy of templates
And here a link with wordpress documention of theme development https://codex.wordpress.org/Theme_Development

This template is use for illustration post type. That mean it's just apply for illustration post type. While the "Hello world" is wp builtin post type and it's use single.php as template in default!
if you want to display the post using your template, change template's header into this:
Template Post Type: illustration, post

Related

new template in wordpress is not displayed under page attributes -> template

i want to integrate several layouts into my theme. so far I have solved it via page.php and page-blue.php because I saw it that way in tutorials. unfortunately the other template is not displayed under the page attributes. i don't see the error. even if i choose a different theme the attributes do not appear. what am I doing wrong?
it should look like this
this is how it looks
this is the page.php
this is the page-blue.php
Change the name of the template, page is reserved word, also create brand-new file with file name other than page.php, which is also reserved file name.
And, for god's sake, name your template files in a way they mean something, self-explanatory.
Example for dummies:
<?php
/*
* Template Name: Some Template
*/
And the file name of the template should be some-template.php inside your theme's folder!
Read more
pls Use This code
<?php
/*
* Template Name: page-blue
* Template Post Type: post
*/
get_header();
?>
instead of this
<?php
/*
* Template Name: page-blue
*/
get_header();
?>

Load custom theme in specific page / post in wordpress plugin (PHP)

I am developing a plugin and I want to show my custom HTML CSS codes on a page or post with a shortcode.
I have this template:
<?php
/**
* Template Name: Raw page
*/
get_content();
?>
and this code on my class:
add_shortcode('my-shortcode', 'callback');
...
public function callback(){
include('view/form.php');
}
now how can I load this template from my function?
Use wordpress function get_template_part.
Check ref here - https://developer.wordpress.org/reference/functions/get_template_part/
And, another suggestion, does your call back/ short code really required ? You can simply write your logic in your primary template file (where you wrote as raw file).
Then put your logic/conditions there and can include different template parts as per your need.

Using archive-page instead of single-page improper?

I want to display all my custom post type project images on a template page, such as single-project.php, but the url doesn't display like I want it to.
It should be 'sitename/projects/' but it displays like 'sitename/projects/slug-of-post'.
Is there a way to modify the 'slug-of-post' ?
OR should I be creating an archive-projects instead to achieve that url since it does display 'sitename/project/' ? or is that wrong to use it like that?
If you want to display the images on a page through using a page template you will be able to choose the page slug as you please.
Then what you want is a page template file like this: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use
This will have something like this in the file header:
<?php /* Template Name: Example Template */ ?>
Alternatively, yes, have an archive-projects.php to display an archive (collection of all content) of the post type.
Make sure your custom post type has an archive.
See has_archive in the documentation of register_post_type():
https://developer.wordpress.org/reference/functions/register_post_type/
This can also be changed for already registered post types (eg if a plugin registered the post type)

Unable to integrate downloaded HTML template in wordpress Theme

I am trying to Convert my HTML template into Wordpress template.But on browser it is only showing content without CSS. I refered the procedure from: https://www.elegantthemes.com/blog/tips-tricks/converting-html-sites-to-wordpress-sites
here I added a below given statement on the top of a CSS file.I am confused about what to write in Theme URI and Author URI, as Right now I am workin on localhost server.
/*
Theme Name: ThemeIntegration
Theme URI: ??
Description: A brief description.
Version: 1.0
Author: You
Author URI: ??
*/
I am only getting Simple html content without styling.
You need to add css and js files either in header or functions.php file, that tutorial is incomplete you can refer this link
If you have only 1 css then you can directly write it in style.css

Wordpress add .php file manually

I have a .php file which uses some WP functions e.g. get_stylesheet_directory_uri(), query_posts, etc... and $wpdb of course.
File it self return JSON data so it is not intended for viewing on its own.
I'm not looking for template, or clicking around in WP dashboard, I just want to know where is the good place in WP file structure to put the .php file and expect WP functions and object to be available.
And also what do I need to include at the top?
You can create custom template in theme root directory or in child theme (child theme is important when you are creating custom template).
template should contain template name, header and footer function.
eg. custom-tpl.php
<?php
Template Name: My Custom Temlate
get_header();
//your other functions and content goes here
get_footer();
after creating template it will appear in your edit page template section under drop down. select custom template for your page and view page you will get your output
You can create a custom page template.
Inside the page template:
<?php
global $wpdb;
[here you will write your code]
?>
On the front pages where you want the json output, use this url
http://domainname.com/wp-content/themes/themename/custompagetemplatename.php
Use your domain name (domainname), theme name (themename) and theme template file name (custompagetemplatename) in place of example names in the url. This url will return you the output for your code.
About this comment in your template:
<?php
/* Template Name: Full Width Page */
?>
You do not need a template name in the header of your file unless you want to use this as a template for pages in wordpress.

Categories