Need to include a custom template page through a plugin - php

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.

Related

Where should WordPress custom page template be placed?

I am just asking about custom page template:
If I put it in the subfolder it will work or it should be placed in the root directory.
For example, I created a template named custom-page-awesome.php and placed it in nytemplate directory.
Please let me know that it's automatically detected when I edit some page or need to include using custom code.
WordPress recognizes the subfolder '/page-templates/'. Therefore, it’s a good idea to store your global page templates in this folder to help keep them organized.: https://developer.wordpress.org/themes/template-files-section/page-template-files/
I believe WordPress does not recognize template files that are not in the root directory of the theme. That is unless you use the following function get_template_part( 'your-template-file' );
more about that here: https://developer.wordpress.org/reference/functions/get_template_part/
You need to put this commented line on top of your template php file in the root of the theme folder. It will display the template in the dropdown menu of pages in wordpress backoffice :

Codeigniter view in Wordpress

I have a website build with Codeigniter and I need to have a blog. It should be a WordPress so what I decided to do is to add "blog" in my .htaccess and install a WordPress in myweb.com/blog
It works perfect.
Now, I need to change my theme header and footer from the one that I have already in my web.
How can I do it?
I have the view at views/common/header.php, but obviously, I can not load it like this in template/header.php
<?php $this->load->view('common/header');?>
If I'm not wrong, I should add any code at header.php in my template folder. So, the question is, what should I change or add on it??
Thanks a lot!
UPDATE
I think there should be a helper I could load in codeigniter in order to call that functions on Wordpress
How can I do it?
You directly cannot call CI view in wordpress file. Inorder to make changes to wordpress header and footer you will need to modify header.php and footer.php file under wordpress theme (wp-content/themes/your_theme_folder).
Also make sure that you do not modify wordpress default theme directly as any changes to default theme would be lost during wordpress updates.
Best practice is to create child theme and then make your changes over there
https://codex.wordpress.org/Child_Themes , here the guide to create child theme.

Wordpress - How to create a custom functions.php file in another folder?

I've seen some tutorials about creating files like my_functions.php, and also custom_functions.php, but all for specific themes. What I'm looking for is a way to create a custom functions.php file that can be used in any theme, is it possible? At least a plugin or put the original file in a different folder. I don't know, I've been looking everywhere and I can't find anything.

How to create a custom drupal cms from starting

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

Retrieving names of over-ridden theme hooks in views 2 (Drupal 6)

I have a created a view (lets call it my_view).
In the theme: information section if the view I have noted one of the suggested template names (views-view--my-view--default.tpl.php (or close to that)), and created my own template file with that name.
This all works fine and when I visit the theme registry, I can see there is a hook there with the name of the template (views-view--my-view--default). However this hook has a type field of 'engine' rather than 'module'. I assume this is to do view the way views works out its own theming?
I want to implement hook_registry_alter to modify this theme hook (and others created in the same way), but I cant work out how to retrieve a list of these hooks.
I tried using array_keys(views_theme()) to get all the views hooks back but this list doesn't contain hooks created by over-riding template files. It only contains the default hooks like views_views_field etc
Is there a way to bring back a list of views theme hooks over-ridden in this way?
I answer here as your last comment seems to indicate you are not interested anymore in pursuing your initial approach, and 600 chars would not be enough, anyhow.
An alternative approach to achieve what you want could be to use the "inheritance" of sub-themes from their parent theme. You could in other words define your user theme as a sub-theme of the admin theme.
In this way the theming engine would search for templates - in the case of a user viewing the site through the user theme - first in the user theme folder, then in the admin theme folder, and then in the module directory.
This is for example the same mechanism used by zen for letting you create your themes with the starter kit.
Hope this helps!

Categories