【发布时间】:2016-01-20 22:55:26
【问题描述】:
此代码显示 WordPress 中最近的 3 篇文章。但是,当点击链接时,每个链接都连接到最近的帖子,而不是与摘录相关的帖子。我需要摘录链接来连接到他们相关的完整帖子。
我没有对此进行编码,但我意识到它已被弃用。我还尝试了 WP 最近的帖子功能和不起作用的简码。 PHP 代码非常混乱,导致很多问题。我对 MySql 的了解非常有限。
$sql = mysql_query("SELECT * from wp_term_relationships where term_taxonomy_id = '3' ORDER BY object_id DESC LIMIT 3 ");
while ($row = mysql_fetch_assoc($sql))
{
$object_id = $row['object_id'];
$sql_posts = mysql_query("SELECT * From wp_posts where ID = '$object_id' AND post_status = 'publish' AND post_type = 'post' ORDER BY ID DESC LIMIT 3");
while($row_posts = mysql_fetch_assoc($sql_posts))
{?>
<div class=" gaming_news_col col-lg-4 col-md-4 col-sm-4">
<h4><a href="<?php the_permalink() ?>"><?php echo $row_posts['post_title'];?></h4>
<p><?php
$content = $row_posts['post_content'];
$post_content = myTruncate($content, 150, " ");
echo $post_content;
?></p>
【问题讨论】: