How to create dynamic url and content like wordpress in php? - php

I want to create dynamic url and content like wordpress platform but I am doing something wrong. Kindly check my code:
<?php
$pages = array("story1", "story2", "story3");
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>This is my page title.</title>
<link rel="canonical" href="http://www.xyz1.com/kids-english-<?php
echo $pages[1];?>.php"/>
<!-- here the url is creating but gives error 404 -->
</head>
<body>
<p>Hello, <?php echo $pages[1];?></p><br>
<?php echo $pages[2];?>
<!-- here the second url is creating but gives error 404 -->
</body>
</html>
Now I want to get the content from database and want to load somefile.php
Here starts my second problem. I create urls by foreach loop but how to load all the content to somefile.php and how will one somefile.php will handle all the different urls and different content created dynamically. I am confused here.
Your suggestions would be welcome.
Thank You.

Well.. applications like Wordpress, Shopware and so on are built on a MVC-Design scheme like every other good coded project.
You can go for frameworks like Symfony or build your own routing mechanism.
All in all it's a little bit more tricky as you did mentioned your thoughts.

Related

How to auto generate dynamically multiple pages changing keywords and meta keywords

I'm new to this but I need to reproduce the same thing as this site is doing for my site too. "Getserialkey.com"
It has a simple page and from all pages are created dynamically by changing just the keyword, all meta tags meta titles meta descriptions will be changed for each page but content template will still be the same.
To do have to template I can reproduce the code in the page source and make changes my own way but how to auto generate many pages dynamically?
Like for example I will have just keywords for a software that I'll input and it will generate the page automatically which will not exactly be the same content because title and tags will be changed.
Please help me do this.
for the start you can write a very simple php script:
<?php
$keyword = $_GET['key'];
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $keyword; ?></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>Keyword: <?php echo $keyword; ?></div>
</body>
</html>
then you can call the site with: index.php?key=test and the keyword test will be shown on the website.
if you want to read the keywords directly from the url you should take a look into htaccess mod_rewrite

"//" on top of every html page using laravel 5 blade layout

I'm creating web application using laravel 5. Everypage has "//" on up-left corner. What is causing this?
The app.blade.php looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Page Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="jumbotron">
#yield("content")
<p>Above content generated by MVC</p>
</div>
</div>
</body>
</html>
Well it certainly isn't anything in the blade template that's doing it.
What is probably happening is that you've got somewhere in your code a line which says echo "//"; or something similar, or a rogue line of code before your <?php block starts -- maybe you were trying to comment out a block of code that includes a <?php block.
That line doesn't have to be in the template; it could be anywhere in the code; if it's run before the template is output, then you will get the kind of effect that you're reporting here.
As for where the line is and what it's doing there, that's something you'll have to work out for yourself. But you can start by searching your codebase for echo or print statements, and for //<?php.

How to remove default text written below body tag in wordpress?

I am facing a problem . As you can see "http://hair-on-demand.com/" a text "page-content" is written in the left-top . I checked header.php but there is nothing written . Anyone knows from where this text is generating ?
Are you using an seo plugin or something along that line b/c the following html is getting injected into <head></head>
<html>
<head>
<meta name="msvalidate.01" content="96AFF80E69D87368573FAEDC4FB70ED1" />
<title>Your SEO optimized title</title>
</head>
<body>
page contents
</body>
</html>
If you are I would disable that plugin or setting in the theme.

seo effect - include file with <html> tag inside

Maybe its a stupied question but i didnt fild any answer for it,
If i have file with the html tag head tag&meta.. and I include him in all my web page, its effect the seo of the site?
I have file named "start_html.php" that have this code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="bla bla.">
<meta name="keywords" content="bla bla">
<meta name="author" content="bla">
<title>bla bla</title>
<!-- CSS: -->
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<!-- JavaScript -->
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
I start every page with this line: <?php include('start_html.php'); ?>
When i check for code error on w3c validator its says that i dont have those tags so the page is not coded good.
If the code from that file is not being displayed in your web page then obviously your PHP code is incorrect and that file is not being included. You need to make sure you have error reporting on and displaying all errors as this will catch this for you.
See this StackOverflow question for how to enable error reporting.
You should have these meta and title tags on all your pages, so including them from PHP is certainly not a bad idea.
However, if the W3 validator tells you these tags aren't there, you should check your output. Perhaps start by 'show source code' in your browser, and see if the tags appear there.
If you try to send your source file for validation, where you have:
<?php include('start_html.php'); ?>
Of course you will get the expected result - no tags, because the source file must be parsed and handled by PHP.
You can give a working link for validation, or copy output in your browser after execution, save the file and send it.

Is it good practice to add a php include of the head section in my pages?

I am creating my portfolio site and I am wanting to include the head section as a php include on my page. Reason being is because the site will have a fair few pages and I will want to make changes later on to things later on like tidying up the css files.
For example;
<head>
<?php include('head.php'); ?>
</head>
as opposed to all this below being shown on each and every page:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/1140.css">
<link rel="stylesheet" href="css/ie.css">
<script src="js/vendor/modernizr-2.6.1.min.js"></script>
</head>
I just didn't know if this was good practice to do, as with this being my portfolio site, I need the code to be correct from the start also as they will probably look into the standard of it also.
What are your opinions and advice people? Thanks.
Yep, it's quite standard. But instead of writing:
<head>
<?php include('head.php'); ?>
</head>
you should put the tags inside head.php. I say it's better because what's inside head.php has no sense without the head tags, so they are kinda linked together. It's good practice to join things so linked into a single file without having to repeat open and close head tags for each page.
Actually, it's even good practice (and commonly used) to have header.php, body.php and footer.php files that has respectively:
header.php
<html>
<head>
...
</head>
<body>
body.php
...
footer.php
</body>
</html>
I'm doing that in my application but I've found that it's not a good idea, because you have many of your stylesheets, javascripts, etc in a php file including the head section and you'll have problems with including it in php files in nested folders. this problem is because of relative paths.
If you can use absolute paths then it's ok otherwise it's not a good idea ...
PHP Includes are used like this all the time. Any time that you have content that will be the exact same on every page, it is very helpful to use an include
This is an old topic but I use
<?php include_once("phpinclude/head.txt"); ?>
phpinclude is it's own folder and I keep the footer, header, and common place info in that folder. .js, and .css has it's own as well.
Edit: I use require now. I would rather have a code fail and die rather than give some random string. They are the same except one dies and the other will print out an error or random code. This is for people learning PHP, not old heads.

Categories