我试图将另一个 Wordpress DB 的最新帖子放在我的 footer.php 文件中,但显然我不理解这个概念。我是 WP 和“循环”的新手,所以任何帮助都将不胜感激!
<!-- .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 ?>