简体   繁体   English

如何通过网站页眉和页脚设计将wordpress博客集成到php网站博客页面?

[英]How to integrate wordpress blog to php website blog page with site header and footer design?

I want to display wordpress blog to my php website's blog page without using and header and footer will be same like my site design but only in content part i want to display blog posts of wordpress blog.. then how it possible??我想在不使用的情况下将 wordpress 博客显示到我的 php 网站的博客页面,页眉和页脚将与我的网站设计相同,但仅在内容部分我想显示 wordpress 博客的博客文章..那怎么可能? Please guide me for this..请指导我这个..

You should create a template in wordpress without header and footer.您应该在 wordpress 中创建一个没有页眉和页脚的模板。 Then get this page using i frame from your php site.然后使用您的 php 站点中的 i 框架获取此页面。

Or you can create a webservice for these blog data from wordpress site and get this from your php site.或者您可以从 wordpress 站点为这些博客数据创建一个网络服务,并从您的 php 站点获取它。

I used this article to pull my blog posts onto my normal website.我使用这篇文章将我的博客文章拉到我的普通网站上。

https://wordpress.org/support/topic/display-posts-on-external-website https://wordpress.org/support/topic/display-posts-on-external-website

1) Here's the code you will want to write in BEFORE the Doctype (so the very first of your HTML): 1) 这是您要在 Doctype 之前编写的代码(因此是 HTML 的第一个):

<?php
//db parameters
$db_username = '###';
$db_password = '###';
$db_database = '###';

$blog_url = 'http://www.jamischarles.com/blog/'; //base folder for the blog.       Make SURE there is a slash at the end

//connect to the database
mysql_connect(localhost, $db_username, $db_password);
@mysql_select_db($db_database) or die("Unable to select database");

//get data from database -- !IMPORTANT, the "LIMIT 5" means how many posts 
$query = "Select * FROM wp_posts WHERE post_type='post' AND        post_status='publish' ORDER BY id DESC LIMIT 5"; 

$query_result = mysql_query($query);
$num_rows = mysql_numrows($query_result);

//close database connection
mysql_close();

// html page starts after ?>
?>
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
</head>

2) Now, the text in the body will be a little bit different. 2) 现在,正文中的文字会有所不同。 Continuing where we left off… Now, the problem here, is that we have dynamically generated content.继续我们停下来的地方……现在,这里的问题是我们动态生成了内容。 That means we write a loop that goes through each table row in the database, gets the title, date, and text, then spits out on the html, and goes to the next row of the database and does the same thing again.这意味着我们编写了一个循环,遍历数据库中的每个表行,获取标题、日期和文本,然后在 html 上输出,然后转到数据库的下一行并再次执行相同的操作。

So if we use a div with same id, it'll show that div up 5 times, each time with a different post.因此,如果我们使用具有相同 id 的 div,它将显示该 div 5 次,每次都有不同的帖子。 This is not acceptable, because it is not valid code, and could mess up the CSS.这是不可接受的,因为它不是有效的代码,并且可能会弄乱 CSS。 So we have to give it a class to be valid, or use tables.所以我们必须给它一个有效的类,或者使用表格。 For this example we'll use divs.对于这个例子,我们将使用 div。

<body>

<?php

//start a loop that starts $i at 0, and make increase until it's at the   number of rows
for($i=0; $i< $num_rows; $i++){ 

//assign data to variables, $i is the row number, which increases with each    run of the loop
$blog_date = mysql_result($query_result, $i, "post_date");
$blog_title = mysql_result($query_result, $i, "post_title");
$blog_content = mysql_result($query_result, $i, "post_content");
//$blog_permalink = mysql_result($query_result, $i, "guid"); //use this line for p=11 format.

$blog_permalink = $blog_url . mysql_result($query_result, $i, "post_name");       //combine blog url, with permalink title. Use this for title format

//format date
$blog_date = strtotime($blog_date);
$blog_date = strftime("%b %e", $blog_date);

//the following HTML content will be generated on the page as many times as   the loop runs. In this case 5.
?>

</body>
<div class="post"></div>

<span class="date">  <?php echo $blog_date; ?>:</code></span><br /><hr   /> 

<a href="http://www.bluebreeze.net/blog"><?php echo $blog_title; ?></a>      <br /><br />

<?php echo $blog_content; ?> <br /><br />

<a href=”<?php echo $blog_permalink; ?>”>This Article</a> <br />
<a href="http://www.bluebreeze.net/blog">More Articles </a>
<?php
} //end the for loop
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM