How to embed a Wordpress blog into a website? - php

Hope someone can help. I am building a simple CV website website which is to include a Wordpress blog. I did use as a temporary solution, but this did not render well on iPhone. I have seen solutions relating to php, but having no prior experience of php I wouldn't know where to start. What i have seen so far online hasn't really given any step by step instruction on how to use the php approach. Any help would be appreciated.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<link rel="stylesheet" href="http://keeleyknight.com/styles.css">
<link href='http://fonts.googleapis.com/css?family=Quattrocento+Sans' rel='stylesheet' type='text/css'>
<script src="http://keeleyknight.com/_js/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="http://keeleyknight.com/_js/modernizr.custom.86080.js"></script>
<script src="_js/myscripts.js"></script>
</head>
<body>
<div id="wrapper">
<div id="content">
<div class="kk_background">
<div class="container">
<div class="blog">
<div class="contact_content">
Blog Goes here
</div>
</div>
</div>
</div>
</div>
<!-- / Homepage -->
</div>
</body>
</html>

You can use this word press plug-in in wordpress and can fetch posts with PHP Guzzle library like below
$client = new \GuzzleHttp\Client();
$response = $client->get("http://domain.com/wp-json/posts?filter[category_name]=test", array('auth' => ['username','password']));
$posts = $response->json();
And render posts in your website the way you want.

Related

PHP Site not working after renaming/adding new page

On my site, I had an index.php with a navbar. Then, I needed to add another page, called second.php, and updated my navbar code accordingly (I have a nav.html file for the navbar, so that I can use JS to load it onto each page of the site). I also added the navbar code to the second.php. However, when I opened index.php, the link to second.php didn't appear.
I tried restarting my computer, restarting my MAMP server, reopening my code editor, reopening the browser, but nothing worked. Then, I tried renaming my files (for both the purpose of testing and because I needed better file names) and updated all instances of the name of the files accordingly. But then this appeared:
followed by a list of the files in my directory. In particular, the site wasn't displaying. Could someone please explain what's happening and how I can fix it?
nav.html:
<body>
<header>
<div class="logo">
<h1 class="logo-text">Welcome!</h1>
</div>
<i class="fa fa-bars menu-toggle"></i>
<ul class="nav">
<li>Home</li>
<li>About</li>
</ul>
</header>
</body>
home.php (formerly second.php):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie-edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<link rel="stylesheet" href="css/style.css?v=<?php echo time(); ?>">
<!-- Font Awesome -->
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.0.7/css/all.css">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Kalam&family=Pangolin&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<!-- JQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<title>Welcome Home</title>
</head>
<body>
<div class="placeholder"></div>
<script>
$(function(){
$('.placeholder').load("nav.html");
});
</script>
hello world
<script src="js/main.js"></script>
</body>
</html>
about.php (formerly index.html) is basically the same as home.php except it has a couple of paragraph tags.
I'm not clear on what isn't working at this point, so I might as well share a working example I have locally. I'm accessing my site at http://localhost/so/, and going to that URL will load any index page I have. I have 3 files inside the /so directory:
nav.html (I removed your <body> tags because those already exist in the other files):
<header>
<div class="logo">
<h1 class="logo-text">Welcome!</h1>
</div>
<i class="fa fa-bars menu-toggle"></i>
<ul class="nav">
<li>Home</li>
<li>About</li>
</ul>
</header>
home.php (accessible at localhost/so/home.php):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie-edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<link rel="stylesheet" href="css/style.css?v=<?php echo time(); ?>">
<!-- Font Awesome -->
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.0.7/css/all.css">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Kalam&family=Pangolin&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<!-- JQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<title>Welcome Home</title>
</head>
<body>
<?php include "./nav.html"; ?>
hello world home
<script src="js/main.js"></script>
</body>
</html>
about.php (accessible at localhost/so/about.php):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie-edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<link rel="stylesheet" href="css/style.css?v=<?php echo time(); ?>">
<!-- Font Awesome -->
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.0.7/css/all.css">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Kalam&family=Pangolin&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<!-- JQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<title>Welcome About</title>
</head>
<body>
<?php include "./nav.html"; ?>
hello world about
<script src="js/main.js"></script>
</body>
</html>
If I rename home.php to index.php then I can go to either localhost/so/ or localhost/so/index.php to access that file.
Slightly related: you shouldn't necessarily use time() as your CSS cache busting variable because it won't cache at all then. You should use a variable that you manually adjust the value of (i.e. $css_cache_bust = "2020061001";) like href="css/style.css?v=<?= $css_cache_bust; ?>" so you can incrementally adjust this as needed.

Having trouble with including PHP file

I am trying to include header.php file inside my index.php file, both of them are in the same folder. However, it is not working.
Here's how I coded index.php file:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/main.css" />
<title>Bootstrap</title>
</head>
<body>
<? php include 'header.php'; ?>
<p>the header file should be above this line</p>
<div class="container">
<div class="row">
<div class="col-md-4">3</div>
<div class="col-md-4">2</div>
<div class="col-md-4">1</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="js/jquery.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
And here's how I coded my header.php file:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>HEADER INCLUDED</p>
<p>HIP HIP HORRAH!</p>
</body>
</html>
I expected that when I open index.php in Chrome, I should see something like
HEADER INCLUDED
HIP HIP HORRAH!
the header file should be above this line
--- the column ---
But the first two lines are not showing up. I am confused what I am missing here.
Change
<? php include 'header.php'; ?>
To:
<?php include 'header.php'; ?>
As <?php means starting of PHP code. But, <? php does not mean anything and is a parse error.
As php is not a language construct like: for, foreach, while, etc...

PHP page blank in Iframe on Mobile but on PC fine

I have a Cutenews program in the iframe on the homepage where myself and others can add a blog, the page displayed in the iframe is a PHP file, when accessing from my mobile the rest of the site loads just not the php file inside the iframe, on PC its fine.
I dont know coding very well so is there a code i need to use to add so the mobile detects the page or something?
Here is my code:
<!doctype html>
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Central Gaming</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><!-- Main CSS -->
<link href="css/style.css" rel="stylesheet" /><!-- Font Awesome -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
</head>
<body><!-- Header -->
<div class="header-wrap d-none d-md-block">
<div class="container">
<div class="row"><!-- Left header box -->
<header class="col-6 text-left">
<h1>Latest</h1><br>
<p>
</header>
</div>
<?php
$number = 5;
include("/home/centralg/public_html/cutenews/cutenews/show_news.php");
?>
</h1>
</div>
</div>
</div>
</body>

PHP include a file with an included file -> scripts and variables get included but seem echo'd

I am having troubles with including a file that has an included file with some js script library's in it.
index.php
<?php
include 'header.php';
?>
<section>
<div>
<p>misc. html</p>
</div>
</section>
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/footer.php');
echo 'test ='.$testVar;
?>
footer.php
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/includes/footerscripts.php');
?>
</body>
</html>
/includes/footerscripts.php
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<?php
$testVar = 'test';
?>
In that scenario, the index file does have this in the source code when ran:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
test =
The scripts are making their way there but are not being executed and the variables aren't coming through either.
When I change the footer.php to include those scripts and variable directly, the variable makes it to index.php, so do the scripts but they don't execute (or not on time?).
Any ideas guys?
I have a weird php5.ini file as I didn't know what all to put in it, if that makes a difference. The include file path seems okay as it still works for the most part.
Thanks,
Matt
Edit: Added the include ('header.php') which works fine and pulls in my header.
That file looks like:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="--">
<meta name="keywords" content="--">
<meta name="author" content="--">
<title>--</title>
<link rel="stylesheet" href="/css/mainstylesheet.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="icon" href="/images/favicon.ico">
</head>
<body>
<header class="nav-top" id="top" role="navigation">
<div class="container">
<div class="home-link">
<img src="/images/logo/logo-p.png" alt="plc" class="logo" />
</div>
<nav class="nav-main">
<ul>
<li>
Home
</li>
<li>
Portfolio
</li>
<li>
Contact
</li>
</ul>
</nav>
</div>
</header>
Edit: Guess I just needed my jquery loaded from the header of the document, because it works that way. I still can't carry variables from grandchild to parent but oh well
According to your example the index.php file is missing something:
<?php
include ($_SERVER['ROOT'].'/footer.php');
echo 'test ='.$testVar;
?>
I assume that you didn't post the whole file, since here the output hmtl here is not valid - missing html opening tag, etc. Could you please provide the whole and/or simplified index file?
Replace all instances of $_SERVER['ROOT'] with $_SERVER['DOCUMENT_ROOT'].

why hyperlink with www does not visible

I was trying to make an hyperlink, I found something I don't understand.
The hyper link below doesn't show up on my html view with www in it.
href='http://www.ringtonematcher.com/co/ringtonematcher/02/noc.php?sid=EULDros&artist=$ringtone_artist&song=$ringtone_title
but when I remove www it start showing up
href='http://ringtonematcher.com/co/ringtonematcher/02/noc.php?sid=EULDros&artist=$ringtone_artist&song=$ringtone_title
Is there any explanation?
Thankyou
EDIT 1
Here is my view source
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/assets/css/style.css" type="text/css" media="screen" />
<title>Music Engine</title>
</head>
<body>
<div id="mainbody" class="wrapper">
<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
SC.initialize({
client_id: "6a43a20c7a9e04da8d722bb01f16ce49",
});
SC.get('/tracks/106285389',function(track){SC.oEmbed(track.permalink_url, document.getElementById("player"));})
$(document).ready(function() {
});
</script>
<div id="player"></div>
<a class="download" href="http://api.soundcloud.com/tracks/106285389/download?client_id=6a43a20c7a9e04da8d722bb01f16ce49">Download</a>
<div class="ringtone_matcher"><a class='download' href='http://www.ringtonematcher.com/co/ringtonematcher/02/noc.php?sid=EULDros&artist=Carly Rae Jepsen&song=Call Me Maybe'>Send Ringtone to your cell</a></div>
</div>
</body>
</html>
what i mean not visible is i can't see it in the browser but i can see it inside the source
www.ringtonematcher.com is on a list of unwelcome advertising sites in AdBlock, which applies a stylesheet which applies display: none to links to it. The site without the www. is not on that list.
Disable your AdBlock extension to see it.
The problem would seem to be from the fact that you aren't effectively "showing" the language of PHP that you have variables in your code.
<div class="ringtone_matcher">
<?php echo "<a class='download' href='http://ringtonematcher.com/co/ringtonematcher/02/noc.php?sid=EULDros&artist=".$ringtone_artist."&song=".$ringtone_title."'>";
echo "Send Ringtone to your cell</a>";
?>
</div>
This would, at least, be a more correct way of doing it.

Categories