WordPress的MySql查询最近的帖子需要链接到个别帖子

时间:2016-01-20 22:55:26

标签: php mysql wordpress

此代码显示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>

1 个答案:

答案 0 :(得分:0)

myTruncate方法将文本剪切到某个特定范围,例如,在您的情况下,它将只显示前150个字符。如果要显示全文,请不要使用myTruncate。只是回应内容。

$content = $row_posts['post_content'];
echo $post_content; 

这应该可以解决问题而不是将文本剪切到指定的限制。

相关问题