dynamic

How to Create a Custom Dynamic Page in WordPress

Spread the love

Custom dynamic pages in WordPress can be done with 2 types, which are mentioned below:

  • Online Live Cpanel
  • Offline XAMPP Server

Custom Dynamic Page in WordPress

Follow us to create custom dynamic pages in WordPress. Dynamic pages in WordPress are very useful, with the help of which we can create Dynamic Websites, we can also insert, delete, update and show the data of the database.

Here you will know how to create a dynamic page and how to fetch data from PHPMyAdmin, hope you will know by seeing this how to create the Dynamic Page.

Follow the steps to Create a Custom Dynamic Page in WordPress

Step1: Check your Active Theme

Open your WordPress Dashboard and go to Check your Activate Theme and Check your Activated Website Theme

Step2: Open PHPMyAdmin Page

Open the PhpMyAdmin page and check your Database name then open it and create a new table there

Create a new table named “reg“.


CREATE TABLE `reg` (
  `id` int(6) NOT NULL,
  `name` varchar(1000) NOT NULL,
  `pass` varchar(1000) NOT NULL,
  `address` varchar(1000) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


INSERT INTO `reg` (`id`, `name`, `pass`, `address`) VALUES
(1, 'khushal', '123', 'naroda'),
(2, 'vishal', '258', 'hiravadi');
Before
After

Step3: Open Sublime Editor

Open Sublime Editor and open the folder containing the code of your WordPress file.

Step4: Create a new Page named template-in.php File.

Open your theme folder and then check your active theme and there Create a new page named template-info.php file.

Step5: Write PHP Code and save it.

Open your template-into.php file and write PHP code and then save this file.

Note:- Here is written PHP’s MySQL query to show you a database from empty PHP MySQL, you can create other pages yourself.

<?php 
//template name: info
// Enter your Host, username, password, database below.
// I left password empty because i do not set password on localhost.
$con=mysqli_connect('localhost','root','','newwebsite') or die("connection failed : ".mysqli_connect_error());

if ($con) {
	// echo "Connection Successfully";
}
else{
	echo "Sorry Some Mistakes is";
}
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }



$sql ="select * from reg";
$data =mysqli_query($con,$sql);
$total=mysqli_num_rows($data);


if ($total=mysqli_num_rows($data)) {
	?>
	<table border="2">
<tr>
<th>id</th>
<th>name</th>
<th>pass</th>
<th>address</th>
</tr>

	<?php
	
	while ($result = mysqli_fetch_array($data)) {

		echo " 
			<tr>
				<td>".$result['id']."</td>
				<td>".$result['name']."</td>
				<td>".$result['pass']."</td> 
				<td>".$result['address']."</td>
				 
			</tr>
		";
	}
}
else
{
 	echo "no record found";
}

?>
</table>

?>

Step6: Create a new Page

open WordPress Dashboard and click a Create a new page.

Step7: Select info Template

Give the title name information of the new page, and on the right side of the page, there will be a dropdown of the template inside the page attributes, select the new template that has been created named Info and publish that page.

Step8: Open your New Page

Open your new information page and check your output.

Output:-

How to add Header and Footer in the new WordPress Dynamic page?

To add the Header and Footer to the new WordPress dynamic page, you need to enter the following code in your page.

<?php 
// add this code in top side
get_header();
?>



<?php 
// add this code in footer side
get_footer();
?>


Spread the love

Related Posts

One thought on “How to Create a Custom Dynamic Page in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *