Is there a way to find the theme file in Wordpress using the name? - wordpress

In the wordpress admin dashboard, on the pages tab, when you edit the page, there's a section called "Page Attributes". One of the options is "Templates", which opens a drop-down list of templates available.
Is it actually possible to find which template name corresponds to which file in the theme editor without looking through every single file in the theme editor?

Shortest way to achieve this is, if you want to get the file name then you can add in the template name directly
<?php /* Template Name: Example Template (example_template.php) */ ?>
So you will see the Example Template (example_template.php) in template dropdown

Related

Add Shortcode to All Post Types

I want to display shortcodes (I'm using fruitful Shortcode) above the post title tag (H1). And I want to display it to all my post (also as a template).
i want to be like this
Thanks.
If you want to adjust the way your single posts are displayed for all the posts, you have to edit the single.php file in your theme folder. You can do this in the backend under "Design" -> "Theme Editor" or you can access the folder and files via FTP.
For your default posts in wordpress you just need to open the single.php file and look for the h1 with your title. It can look something like:
<h1><?php the_title(); ?></h1>
Above that (if you want to display it above), you can put your shortcode with the do_shortcode() function:
<?php echo do_shortcode('[name_of_shortcode]'); ?>
If you are not using normal posts of wordpress but custom post types or something else, please have a look at the wordpress template hierarchy to find out, which file to edit or how to name the new files for creating template files: https://developer.wordpress.org/themes/basics/template-hierarchy/
If you are using a theme that is not made by you, you should make sure you keep your theme updateable. So if you overwrite the single.php, with the next update of your theme, the file will not have your edits. You need a child theme, if you want to keep your parent theme up to date but also customize it in the page templates. Here is a nice tutorial for child themes: https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/

Changing the "standard template" name of the single.php post template

I have a Wordpress website, now i want to change the post template name how it displays in the Wordpress CMS. Now it's saying "Standard template", i want to rename this to "News", just for usability reasons.
I can't find a way to do this. I know you can create new post templates by creating new files, but it always takes the single.php as standard template. I'm also using a child-theme, so i dont want to delete the single.php file, just rename the text: "Standard template".
Thanks in advance.
I tried creating a new post template file with a custom title. This doesnt solve problem, as the single.php file will still be the standard one (i dont want the user to have to change the template).
You can use another single.php for another post type for example if you have news registered as a post type you could have a single-news.php and that file then would server all the single views of postype = news. But from what i understand you would like to create a template appearing to the user with a different name. For that the best practice is to create a directory inside your child theme and name it page-teplates. Inside this directory you can create as many different templates you want and wordpress will recognize them but adding the following code at the top of each template. For the sake of the example lets say i want to create a contact page template. I will create a contact.php file inside the directory page-templates and have these lines of code inside.
<?php
/**
* Template Name: Contact
**/
get_header();
/* My templates Code/Design Here */
get_footer();
The possibilities are endless.
The code in this post will generate a dropdown box similar to the one that you see in pages.
All it requires is a little editing of your child themes functions.php file .
In most cases, you just need to copy your single.php file to a new file name in your child theme and edit the functions.php file in your child theme. Name your templates as seen in the code Dimitrios posted.
consider using the premium elementor page builder to create custom post templates that you can apply at will.
Try a plugin like Post Custom Templates Lite

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.

How to name different footer files which can be selected in wp-admin's page editors

Seen this done before in other templates, just wondering if anyone here knows how to do this.
I have one template I have created, and two hard coded footer files. footer.php and footer-1.php.
I want to be able to select between using either footer.php or footer-1.php in wp-admin via the pages editor.
So far all I have found so far is adding something like this to the top of the file:
Template Name: footer_1
However, this requires that a secondary header and other files are also included, it won't allow just a change of footer alone.
Can anyone tell me how I can name different footer files so that wordpress detects them in wp-admin and allows me to switch between them.
I do not require adding widgets to these, there is simply two styles of footer and they have no correlation to page or category to hard code, they have to be selected in the admin area manually.
To dynamically change your footer with a admin editor option, do the following:
Open the page you want to customize in editor
Locate Custom Fields meta box in editor (If it is not visible tick the box Custom Fields in the Screen options dropdown at top right)
Select Add Custom Field in Custom Fields meta box
Enter footer_template in Name field and an arbitrary id in the Value field
Select Update to save your settings
Open your theme folder and locate page.php file
Open page.php file and locate the very last line <?php get_footer(); ?>
Delete the line in step 7 and add the following:
<?php
$scriptonomy_footer_meta = get_post_meta(get_the_ID(), 'footer_template', true);
get_footer($scriptonomy_footer_meta); ?>
Save and close page.php file
Make a duplicate of footer.php and name it footer- plus any arbitrary id you chose in step 4, ie: footer-1.php or footer-two.php
Now you can assign any custom footer to any page. You can do the same for the header as well using this technique.

How to customise HTML structure in Drupal view block

I am currently developing a website in Drupal. I have a load of news articles which are of content type 'news'. I want to create a widget to show at the bottom of several pages listing the latest articles. I have managed to achieve thus far by creating the view with the fields I want and then making the view available as a block.
The problem is the format in which the articles are being listed in the view. Ideally I would like to customise the HTML. I understand that I can create a custom template to target views/blocks but I haven't quite got a full understanding of it yet, and find the Drupal documentation to be quite dry and therefore hard to find what I need from.
Any pointers would be helpful.
Go to your view edit page and select "table" as your view mode.
Go to "Theme information" and look for the desired (style output) template name.
Copy this name and create a new file in your theme folder using this name. I.e.: views-view-table--view-name-block.tpl.php.
In this file you can use the following structure (as an example) to get the values of the fields:
<?php foreach($rows as $row):?>
<div>
<h2><?php print $row['title'];?></h2>
<p><?php print $row['field_custom'];?></p>
</div>
<?php endforeach;?>
Don't forget press rescan theme files after you saved the file in the view theme section.
You can get as specific as you want. Create a block view next to the default or page view and you will see specific file names in the "Theme information" section.

Resources