简体   繁体   English

wordpress博客与php网站连接

[英]wordpress blog connects with php website

I have wordpress blog and php website. 我有wordpress博客和php网站。 I'd like to put the information about new articles on wordpress blog to the php website. 我想将有关新文章的信息放在wordpress博客上到php网站。 I did something. 我做了什么 I have titles of articles. 我有文章标题。 But I need featured images and descriptions as well. 但我也需要精选图片和说明。

Here is code which I put on my php website. 这是我放在我的php网站上的代码。

<?php 
      // connection with wordpress
$db = mysql_connect ("localhost", "...", "....");
mysql_select_db ("...", $db);

$result_redaktor = mysql_query("SELECT * FROM wp_posts WHERE post_status = 'publish' ORDER by post_date DESC LIMIT 10", $db);

if (!$result_redaktor)
{

exit (mysql_error()); 
}

if (mysql_num_rows($result_redaktor) > 0)

{
$myrow_redaktor = mysql_fetch_array($result_redaktor);

do
{
printf ("<div class='main'>
    <a href='http://redaktor.11klassniki.ru/%s'>%s</a></div>"
    , $myrow_redaktor["guid"], $myrow_redaktor["post_title"]);
}

while ($myrow_redaktor = mysql_fetch_array($result_redaktor));
}
else 
{
echo "<p>no data.</p>";
exit ();
}
include ("blocks/bd.php");
?>

I don't know how to get featured image and text (lead, which goes before tag more). 我不知道如何获取特色图片和文字(线索,它在添加更多标签之前)。

PS My site and my blog are in the same hosting. PS我的网站和我的博客位于同一托管中。

This code allows to see titles. 此代码允许查看标题。 It works. 有用。 But I need to add pictures to titles. 但是我需要在标题中添加图片。

How can I customize next code 我如何自定义下一个代码

  $thumbnails = get_posts('numberposts=10');
  foreach ($thumbnails as $thumbnail) {
    if ( has_post_thumbnail($thumbnail->ID)) {
      echo '<a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
      echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail');
      echo '</a>';
    }
  }

  echo get_the_post_thumbnail( $post_id, $size, $attr ); 

You should use wordpress RSS, read this article for more info: http://www.wpbeginner.com/beginners-guide/what-is-rss-how-to-use-rss-in-wordpress/ 您应该使用wordpress RSS,有关更多信息,请阅读此文章: http : //www.wpbeginner.com/beginners-guide/what-is-rss-how-to-use-rss-in-wordpress/

Or, if your site and your blog are in the same hosting, you should include wp-load.php file in your php site and use all the function wordpress to show posts. 或者,如果您的站点和博客位于同一主机中,则应在php站点中包括wp-load.php文件,并使用所有功能wordpress来显示帖子。

One example from http://davidwalsh.name/wordpress-recent-posts : http://davidwalsh.name/wordpress-recent-posts中的一个示例:

// Include the wp-load'er
include('wp-load.php');

// Get the last 10 posts
// Returns posts as arrays instead of get_posts' objects
$recent_posts = wp_get_recent_posts(array(
    'numberposts' => 10
));

// Do something with them
echo '<ul>';
foreach($recent_posts as $post) {
    echo '<li><a href="', get_permalink($post['ID']), '">', $post['post_title'], '</a></li>';
}
echo '</ul>';

Enjoy your code! 享受您的代码!

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

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