我想從另一個WordPress的數據庫中最近的帖子在我的footer.php文件,但顯然不理解這個概念。我對WP和「循環」很陌生,所以任何幫助將不勝感激!Wordpress從另一個分區獲得最新的帖子
<!-- .entry-content -->
<?php
$originaldb = new wpdb('db_name', 'db_password', 'db_user', 'localhost'); //This has been replaced obviously.
$newestPost = $originaldb->query("SELECT * FROM wp_posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 0,1;");
$newestPost = mysql_fetch_array($newestPost);
if ($newestPost) {
foreach ($newestPost as $newPost) {
?>
<header class="entry-header">
<div class="entry-meta">
<?php echo '<span class="entry-day">'.get_the_date('j').'</span><br><span class="entry-month">'.get_the_date('M').'</span>'; ?>
</div>
<div class="title-box">
<h2 class="blog-title"><a href="<?php //the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php echo '<a href="'.get_author_posts_url(get_the_author_meta('ID')).'">'.get_the_author().'</a>'; ?>
</div>
<div class="clear"></div>
</header>
<div class="entry-content">
<?php the_excerpt(); ?>
</div>
<?php } //end foreach ?>
<?php } //endif ?>