How to add a file to wordpress theme from apparence->editor? - wordpress

How to create a new file in my wordpress theme without using ftp client ?
thanks !

Using touch(); PHP function, which creates a new file in the specified directory. This is how I suggest doing it (and admittedly, there are cleaner ways, but this will get the job done, quickly and effectively)…
Open header.php — then write this code in the very top of the file:
<?php touch('wp-content/themes/YOUR_THEME_DIR/FILE_NAME.php');?>
Replace YOUR_THEME_DIR with the directory in which your WordPress theme lives.
Then, replace FILE_NAME with the name of the file you want to create.
Once that’s all done, save Header.php and go to the homepage of your site.
As soon as the homepage loads, it will create that new template or theme file.
Source :
https://www.webmechanix.com/how-to-create-a-new-theme-file-in-wordpress-without-ftp-access/

You can use a plugin called WPIDE found here https://wordpress.org/plugins/wpide/
This plugin will allow you to edit and add folder and files in your project.

Related

In Wordpress website, connecting to another web_based application

I want to create a page in word press website, that shows information from external DB by API. What should I do?
But other pages and theme are in the Wordpress database.
Thanks in Advance
Set up a custom template. It can contain all the custom code you need, such as the API to call the external database. You create a new template by copying and modifying the page.php file from your theme. Just remove the parts you don't want and at the top put your new template name in a comment line like this:
/* Template Name: External-DB-Page */
Save that to a file such as external_db.php, upload it to your theme or child theme directory and then in your functions.php you include the file by adding
require_once 'external_db.php';
This new template called "External-DB-Page" will now be a selection available when choosing a page template for any page in WordPress.

Is it possible to create a custom page and use WordPress Codex?

I want to ask that can I create a file with my favorite name and use WordPress Codex in it ? How I can do that ? I want to load posts of a unique category in it ...
Note: I don't want to create a Page from WP Dashboard.
Thanks !
It will be better to create a page template and write the code for displaying post from category. Then assign your template to any of the Page in Wordpress Dashboard.
Look at the Wordpress Template Hierarchy
To load posts of a unique category (e.g. movie_cat) you can create a file named category-movie_cat.php.
Click here for a larger version of this picture
If you want to create a new php file which will work with your WordPress install, create your new file and copy/paste this piece of code, name this file like you want:
define('WP_USE_THEMES', false);
/** Loads the WordPress Environment and Template */
require ('wp-blog-header.php');
Correct the path for wp-blog-header.php according to where your new file is placed (in this example, the file is at the same level of wp-blog-header.php).
Add your special script to this page and you're done !
Note that this method is a way to display your content in another way than the activated theme. If you want to add function in your plugin or theme, you only need to include it in your functions.php or main plugin file to use WordPress functions, db...
Hope it helps

How to Unset title ('Search results') on Search results page?

How to Unset title ('Search results') on Search results page?
I'm still noobish and I was trying this:
function mymodulename_preprocess_search_result(&$variables)
{
$variables['title'] = NULL;
}
You can not change it with a preprocess since the sentence is just a printed string in the template not a variable. So you have to alter the template.
In the templates folder of your theme, duplicate the template from /root directory of your site/modules/search/search-results.tpl.php.
And edit this file as you wish.
The theme template file will be automatically called instead of the one in the core.
You just need to change output rendering. Easy way to do this is to change search core module template file.
Go on:
\modules\search\search-results.tpl.php
In that file just delete output string or replace it with empty one. Find next line in code:
<h2><?php print t('Search results');?></h2>
You can delete whole row there or you can change it to:
<h2><?php print t('');?></h2>
NOTE:
When you change core modules you should pay attention you don't overwrite it with release which comes in new Drupal core (in case you want to upgrade your Drupal core).
If you not sure you will replace this file in future (during possible module or even entire Drupal core update) you might consider copy this file in your theme template folder. After putting that file in your theme template files folder you just need to clear the cache and that file will be called instead of one in core module.
#Laurent Thank you for your update.
Hope this helps.

Creating a wordpress theme

Just want to know that if I'm going to create a new wordpress theme, what about functions.php, should I need to create a new functions file, or just copy it from other wordpress theme. I have read codex but it only tells about the templates needed to create a new theme.
The theme functions file is a template used by Word-press themes. It acts like a plug-in and gets automatically loaded in both admin and front-end pages of a Word-press site.
The functions.php file can be found in your theme’s folder.
You don't need to create a new functions.php file when you want to put your own function in function.php just paste that code in your themes functions.php file.
You can look into these Reference Links to understand more about function.php file :-
Functions_File_Explained
You don't need a new functions.php file if you don't want custom functions in your theme.
See this thread for more information - not including functions.php doesn't make any difference for your custom theme.

Can my WordPress custom templates be in the plugin folder or only in the theme folder?

A WordPress theme I am developing has an integrated custom post type called "albums" which utilizes a few custom templates (archive-albums.php, content-albums.php, etc.). What I want to do is transfer this functionality, along with the template files, into a plugin for the sake of portability.
I transferred the CPT code from the functions.php with success, but when I try to move the template files from the theme folder to the plugin folder, things fall apart. I feel like it should be simple to somehow register the templates so WordPress knows to load them.
Can my WordPress custom templates be in plugin folder or only theme folder?
Things are falling apart because when you move those files, you're violating WP's native template hierarchy. You'll need to explicitly declare the location of those files. Using the archive as an example, you could add something like this to functions.php (to tell WP to look elsewhere):
add_filter('template_include', 'include_album_template', 1);
function include_album_template($template_path) {
if(get_post_type() == 'albums') {
if(!is_single()) {
$theme_file = 'path-to-your-plugin-directory';
$template_path = $theme_file;
}
}
return $template_path;
}
Obviously you'd use your own path, and I wrote this hastily so you might want to refactor.
I have the same issue. I'm already using add_filter ('template_include', ...) problem is that I need to specify a file to return, and in this case being it,index.php. This raises an issue with the theme not running entirely as if installed via themes folder, because what I need is to have WP selecting the appropriate file to render without any conditional logic from my part. So if it is a post it will select the single.php and so on. Another problem raised with this method is that in header.php the call get_header (); ignores the local file header.php and loads the default theme installed file instead.

Resources