How to create a custom drupal cms from starting - php

Actually i need to know how and where the page content for each drupal page comes. So i tried to integrate my own custom theme to drupal. In the tutorial they are saying like i need to create a custom folder and copy one of the default theme like garland/pushbutton to that folder. I got it correctly, but when i check the files and functions in these template the functions used to create the template are different. For example in pusbutton theme we don't have template.php but in garland we must have a template.php file to show the content. So i am getting confused, is drupal don't have standered way of or functions or files to create a custom templete? Also how the data comes in each page?

It is a good practice to copy the existing core theme folder and put inside /sites/all/themes.
Each theme in drupal is different from the other. For instance the template.php is used
For all the conditional logic and data processing of the output, there is the template.php file. It is not required, but to keep the .tpl.php files tidy it can be used to hold preprocessors for generating variables before they are merged with the markup inside .tpl.php files.
The only required file involved in creating a theme is .info file.
Learn more about How theme works

Related

WordPress: Child theme + Custom Post Template

I'm building a WordPress site using Elementor theme. I'm quite new to WordPress development.
I'm using a custom post type for a group of entities. I need to create a custom post template for these. I'm using the default Hello Elementor theme. I've created a child theme, so that I'm not making code changes to the base theme, in order to avoid issues when updating.
In the child theme, I've created a template for the custom post type, using the structure described in the documentation here, by creating a file called single-{entity name}.php. This works, as I can modify this file, and it'll affect the results rendered when I try and access one of these pages.
My problem is that the header and footer disappears and it seems to disregard everything from the parent theme. If I copy this single-{entity name}.php file into the parent file, it works just as expected with the header and footer showing.
I'm guessing there's some logic that intercepts the render in the parent theme and adds the header and footer, but I don't know how it actually works.
I'm not sure whether I should keep it in the parent theme to get this to work of if I should move it back to the child theme and then add some configuration in order to get the header/footer to show? If the last option is the recommended way, guideline on how to achieve this.
Goal is to be able to have a file that governs the template for all entities of this type, keep the header/footer and not be at risk of breaking when updating the theme and/or WordPress.
Have you tried to copy an existing file (exact copy of single_post.php for example) just to see if it works ?
If the page have header and footer, then the error is on this php file, otherwise it's somewhere else.
You can have an idea like that

Wordpress same custom post template for different languages

I have a Wordpress webpage where a former web developer created a custom post type using Pods pulgin, on this custom post type there is a post that we can call "Ejemplo", that post uses content-single-ejemplo.php to be build but the english version "Example" is being created with content-single.php.
What should I do to use the same content-single-example.php for the same post on both languages instead of content-single.php for the english version?
(We are using the plugin WPML for translations)
I've already tried cloning the content-single-ejemplo.php and rename it as content-single-example.php but it still doesn't work.
content-single.php or content-single-post_type.php are NOT part of the regular Wordpress template hierarchy nor a post template file. In your case it's probably a custom template part. Meaning that it as no default fallback nor redundancies and as no ties to the Wordpress core functionalities.
A template part is loaded on the front-end via the handy function get_template_part.
Loads a template part into a template. Provides a simple mechanism for child themes to overload reusable sections of code in the theme. Includes the named template part for a theme or if a name is specified then a specialised part will be included. If the theme contains no {slug}.php file then no template will be included.
The template is included using require, not require_once, so you may include the same template part multiple times.
For the $name parameter, if the file is called "{slug}-special.php" then specify "special".
- Source # https://developer.wordpress.org/reference/functions/get_template_part/
In short, the content from a template part is just a reusable piece of code.
Currently both of them (content-single.php and content-single-ejemplo.php) are ALREADY using the same end-file, which is probably single.php and I'm guessing that content-single.php and content-single-ejemplo.php are just loops, one for each language.
If you want somebody to be able to help you, you should include the content from both file, content-single.php and content-single-ejemplo.php and the parent file, which is probably single.php.
Learn more
Visual Overview Template Hierarchy

Create custom theme from scratch in wordpress without using default

I am developing a custom theme from scratch in WordPress, So i have few questions about it.
1) Is custom theme create using default theme.
For example ( Suppose i have copied twentyseventeen and paste it and rename it my_custom_theme then after changes as per HTML in particular files (header,footer etc)
2) Should i create necessary files for theme like (header, footer, index, style, page, function etc)
So i want to clarify which way should i go for create a custom theme 1st or 2nd.
Someone please help me for this
I would recommend using underscores
It is a starter theme foundation setup built for that purpose, it has all the needed files templates and uses the best practices and organised code.
You will take it and build your theme from it.
There is also understrap which is underscores with bootstrap styling
this will save you alot of setup and preparation time, you can delete and remove any code or any template you not using.

Need to include a custom template page through a plugin

is there any way to include a custom template from a folder inside my plugin page into the Wordpress system so that when I, for example create a new page/post, it can show as one of the template choices other than default of course.
I have seen this link here WP - Use file in plugin directory as custom Page Template? but does not seem to talk about the stage were Wordpress checks for custom templates in the themes directory and how to make it look else where.
It's not in the documentation because WordPress doesn't look elsewhere. Your best bet would be to create a template page in your theme folder, call it what you want, and then use include() to pull the contents of your template file in the plugins directory into the file in your theme directory, which would allow WordPress to see it.
I think the only other way to accomplish this would be to mess with Core, which is very bad practice.

Drupal 7 custom template file for certain content type

i am currently working on a drupal 7 project. I wrote a custom template for a certain content type. The file is named correctly node--type.tpl.php and it's displayed correctly too. but the other regions and blocks are not visible. other custom templates show all regions and blocks. I'd like to mention two things,
i'm not a drupal lover/hero
i'm expanding an existing project.
A few things to check:
Make sure you've also copied across the core node.tpl.php file to your theme folder; the template overrides for nodes won't work without it.
Make sure your file is properly named, e.g. for a content type with the name of home_page the template file will be called node--home_page.tpl.php.
Make sure you've cleared Drupal's caches since adding the new template files; the theme registry is cached so a clear is necessary to pick up changes.
See Drupal 7 Template (Theme Hook) Suggestions for more information on the general subject.
As an aside, the node template file doesn't have any blocks/regions in it, they will always be contained in page.tpl.php, or some derivative.

Categories