繁体   English   中英

wordpress博客与php网站连接

[英]wordpress blog connects with php website

我有wordpress博客和php网站。 我想将有关新文章的信息放在wordpress博客上到php网站。 我做了什么 我有文章标题。 但我也需要精选图片和说明。

这是我放在我的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");
?>

我不知道如何获取特色图片和文字(线索,它在添加更多标签之前)。

PS我的网站和我的博客位于同一托管中。

此代码允许查看标题。 有用。 但是我需要在标题中添加图片。

我如何自定义下一个代码

  $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 ); 

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

或者,如果您的站点和博客位于同一主机中,则应在php站点中包括wp-load.php文件,并使用所有功能wordpress来显示帖子。

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>';

享受您的代码!

暂无
暂无

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

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