Keeping WordPress theme and layout when opening custom php file - php

I'm trying to incorporate some custom made php files in a WordPress site.
In these files made links to other files.
<?
echo "" $row['Name'] . "<br> ";
?>
This works fine with an php-execute plugin for WordPress. The only thing is that the show.php opens without the WordPress theme and layout.
How can I make a link so that a new php file will open in the same (side)bar/frame with the same layout as the WordPress page?

you need to create a custom template for that
The syntax is something like this:
<?php
/*
Template Name: My Custom Page
*/
get_header();
?>
Here your HTML coding goes
<?php get_footer(); ?>
This will give you the look and feel you are looking for!!

Found my own work around
Create a page in WordPress (page_id=x) and include an exec-php plugin.
Include this code on the page.
<?
$page_include =$_GET["page_include"];
include $page_include;
?>
If you want to show a custom page in the wordpress them make the following link:
<?
echo " link "
?>

Related

Need to create a custom php page for a wordpress site having no theme folder

I am new to WP, so please excuse if I ask anything silly.
I have WordPress site which have that created using builder and doesn't use page template of theme folder, everything is built on page builder. I also have other project that I've created on core php.
Is there a way to integrate Core PHP website with Wordpress website?
Creating a Page Template
Creating a page template is extremely easy. Create any new file in your theme (wp-content/themes/your-theme/my-custom-page.php) and start the file with a comment block like so:
<?php
/*
Template Name: My Awesome Custom Page
*/
get_header();
?>
/*
Code Here
*/
<?php
get_footer();
?>
You need paste php code inside this template file. When you submit for then redirection action will be page with custom template page.
Reference :
https://premium.wpmudev.org/blog/creating-custom-page-templates-in-wordpress/
Video :
https://youtu.be/1ZdHI8HuboA

Wordpress conditional menu plugin does not work

I am creating a wordpress website and I am using the conditional menu plugin
but that does not work.
I have the home.php template I added using the code
<?php if(!is_front_page() && is(home)) ?>
and I have used the
<?php the_content(); ?>
function in the index.php.
Moreover I have the following specific page templates:
about-us,photos,vidos,contact
I have added those with the following code:
<?php
if(is_page(about-us)){
get_template_part('template-parts/about');
}
?>
The problem is the menu is not showing in the specific pages.
Can someone help me to fix it?
P.S:I used other plugins as well (like the Elementor plugin).

Can't see php-content from custom template in WordPress

I'm trying to create a custom template for a small wordpress site, the template should display some data from the database.
But I can't get PHP to output anything on the pages, I've written a few echo's just to get something but can't see anything.
I can, however, add the page through "Pages" in WordPress, that works just fine and displays an empty page (or with text if I write something in the text box)
To set up the template I created a child template of my original template, the CSS file in the child template works just fine.
I added the custom page called "petitionlist.php" in the root of my child-theme, the code I added for testing is as following
<?php
/*
Template Name: petitionlist
*/
get_header();
echo "test test test";
$test = "testtetsttest";
echo "<h1> this is a test</h1>".$test; ?>
<h1>Hello wordl!</h1>
<?php get_footer(); ?>
Attached is a screenshot of my folder-structure, the petitionlist.php file in wechange-child is the file I'm working on.

WordPress Custom Template - Divi module shortcode displays as text

I have written a head navigation using the full-width code module in Divi. It is in my Divi library as a global module and works perfectly with most of my pages, but not the ones that are using my custom templates.
The way I am displaying the module is by using it's shortcode at the bottom of my child theme's header.php right before the closing header tag:
<?php echo do_shortcode('[showmodule id="XXXX"]'); ?>
where XXXX is the actual id. But on the pages using custom templates the module displays as plain text like so:
'[et_pb_section global_module="my modules id"][/et_pb_section]'
I have also tried changing the code to:
echo apply_filters('the_content','[showmodule id="XXXX"]');
however, the same issue occurs.
Any Ideas?
I found a good method for this in a thread in the Divi Support Forum, which this dude also explains in a video:
https://www.youtube.com/watch?v=PJqcfz5NyZs
Once you get the global Module number from the URL when viewing it in the Divi Library, the shortcode syntax to load the global module in php is:
<?php echo do_shortcode('[et_pb_section global_module="###"][/et_pb_section]'); ?>
One drawback is that loading a module through a php template file does not allow it to be editable through the Visual Builder.
So, I made a modification to this so I could have an easier place to edit the global footer by adding it to my site's homepage Divi layout, then adding this snippet in my footer.php template file to load on the rest of the pages:
<?php if ( !is_front_page() ) : ?>
<?php echo do_shortcode('[et_pb_section global_module="2310"][/et_pb_section]'); ?>
<?php endif; ?>
This way I can easily have a client use the Visual Builder on the homepage to edit the global footer, instead of having to find it in the Divi Library, which they would likely forget and takes extra click to get there.
Please try adding this code. It will solve your problem
<?php echo do_shortcode('[showmodule id="my modules id"]'); ?>

Wordpress: prevent code dupplication through similar page templates

I'm currently doing some refactoring on an existing wordpress website that uses 9 page templates and I have the following problem:
All these pages have the same code written to display the header, the sidebar etc.
I wonder if it's possible for me to have a "parent" page that would be in charge of displaying those recurring template parts?
The reason I can't manage to do it is that only the page template file is called and no parent file.
That's what I would like to achieve:
<?php
// page-master.php
get_header();
get_sidebar();
get_page_content(); // includes the actual page template.
get_footer();
?>
I hope you understand what I'm looking for :)
Thanks in advance!
Create template your-name.php
Put that code
<?php
/*
Template Name: Your Name
/*
get_header();
get_sidebar();
get_template_part(template-hepler/your-name-content.php); // includes the actual page template.
get_footer();
?>
Create your-name-content.php in template-helper folder
And write there your page content
Assing that template to nessasary pages

Categories