I tried reading the WordPress codex about integrating WordPress into an existing website.
I tried using the header information
<?php /* Short and sweet */ define('WP_USE_THEMES', false);
require('./wp-blog-header.php'); ?>
And then the test code
<?php // Get the last 3 posts.
global $post; $args = array( 'posts_per_page' => 3 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br />
<?php endforeach; ?>
Another code I added to make the page only for logged in users:
if ( ! is_user_logged_in() ) { // Display WordPress login form:
wp_login_form($args);
This code does make the login show, but when I log in, it cannot remember that it is logged in, and the functions (blog posts) will not show. The funny thing is, the login form (as called by the wp_login_form) shows, but I cannot log in. This is quite anoying, as the information in the codex doesn't work Integrating Wordpress with Your Website
It does not work. Can someone help me? I tried posting at the WordPress forum, but no help there
New edit 07th november: This is how the PHP file looks like now. It's called lite_index.php and includes the wp-load, and because of that I believe the login form under here shows, bt still it cannot login.
<?php
//define('WP_USE_THEMES', false);
//require('lite/wp-blog-header.php');
define('COOKIEPATH', '/');
require('lite/wp-load.php');
require('loggin_check.php');
//require(dirname(__FILE__) . 'lite/wp-load.php');
//header('Content-Type: text/html; charset=ISO-8859-1');
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php
endforeach;
?>
<h1>Lite v4</h1>
<?php
if ( ! is_user_logged_in() ) { // Display WordPress login form:
wp_login_form($args);
} else {
wp_loginout(index.php); // Display "Log Out" link.
echo " | ";
wp_register('', ''); // Display "Site Admin" link.
echo "<br />\n";
}
?>
I tried reading the WordPress codex about integrating WordPress into an existing website.
I tried using the header information
<?php /* Short and sweet */ define('WP_USE_THEMES', false);
require('./wp-blog-header.php'); ?>
And then the test code
<?php // Get the last 3 posts.
global $post; $args = array( 'posts_per_page' => 3 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br />
<?php endforeach; ?>
Another code I added to make the page only for logged in users:
if ( ! is_user_logged_in() ) { // Display WordPress login form:
wp_login_form($args);
This code does make the login show, but when I log in, it cannot remember that it is logged in, and the functions (blog posts) will not show. The funny thing is, the login form (as called by the wp_login_form) shows, but I cannot log in. This is quite anoying, as the information in the codex doesn't work Integrating Wordpress with Your Website
It does not work. Can someone help me? I tried posting at the WordPress forum, but no help there
New edit 07th november: This is how the PHP file looks like now. It's called lite_index.php and includes the wp-load, and because of that I believe the login form under here shows, bt still it cannot login.
<?php
//define('WP_USE_THEMES', false);
//require('lite/wp-blog-header.php');
define('COOKIEPATH', '/');
require('lite/wp-load.php');
require('loggin_check.php');
//require(dirname(__FILE__) . 'lite/wp-load.php');
//header('Content-Type: text/html; charset=ISO-8859-1');
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php
endforeach;
?>
<h1>Lite v4</h1>
<?php
if ( ! is_user_logged_in() ) { // Display WordPress login form:
wp_login_form($args);
} else {
wp_loginout(index.php); // Display "Log Out" link.
echo " | ";
wp_register('', ''); // Display "Site Admin" link.
echo "<br />\n";
}
?>
Share
Improve this question
edited Nov 7, 2018 at 15:11
Ole Lasse Bjellaas
asked Nov 1, 2018 at 21:00
Ole Lasse BjellaasOle Lasse Bjellaas
234 bronze badges
2
|
3 Answers
Reset to default 1I started writing a pretty long comment, but I figured I would write it as a solution instead.
If you mix all your files in one big jumble, then it probably wont work. But if you put WordPress in a subdirectory, then it would work (that's how I used to do it).
REMEMBER!!! If you already have a working WordPress-installation and want to move the posts, then you can't simply move the files. You'd have to follow the right procedure, which is explained here.
Example of correct file-structure, mixing a static website with WordPress:
|-your-index.php
|-your-page-1.php
|-your-page-2.php
|-your-css
| |-your-styles.css
|
|-your-js
| |-your-js-file.js
|
|-wp <-- Put your entire WP-installation in a folder
|-wp-content
| |-themes
| |-uploads
| |-...
| |-...
|
|-wp-includes
| |-...
| |-...
|
|-wp-admin
| |-...
| |-...
|
|-wp-config.php
|-wp-blog-header.php
|-...
|-...
This way you can call
<?php require( $_SERVER['document_root'] . '/wp/wp-blog-header.php'); ?>
Then you can keep your own static files and your WordPress-installation seperate and make it work. This is how I used to do it, and that worked.
Flipside
I can see (by Googling a bit), that it looks like that @Bob's suggestion has become more popular. Here's an example, using wp-load. I must admit, that I don't know what the difference is between the two.
This solution suggest a third way of doing it.
But all things considered... Regardless of which way you load WordPress, then I think that it's your file structure that is your current challenge (if I'm not mistaken). WordPress needs it's own isolated environment (folder), so it can make it's URL and call the files as intended.
Final word
But as I suggested in my comment. I used to do this, - and I wish I never did. I wish I had baked my static website into a WordPress-theme.
Have you tried using the following?
require(dirname(__FILE__) . '/wp-load.php');
Note that this requires WordPress to be installed in the root directory of the website.
You can learn step by step by click below link:
https://youtu.be/LFBe3KkyUA4
You can comment in comment section for any query, We will answer in next 2 hours.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742404110a4437495.html
require('./wp-blog-header.php');
makes it look like that your WordPress-files are in the root-directory (amongst your other files). I think I would keep WordPress in a folder by itself, to avoid wierd collisions. I'm not sure if that's the right way to do it, though. ... Another thought that pops into my head is, that have you considered doing it the other way around (by putting your website into a theme, inside WordPress). I used to make websites like you describe, and it becomes a mess. But that's just my personal preference. – Zeth Commented Nov 6, 2018 at 0:49