将 the_contents 附加到循环之外 [英] Append the_contents outside of the loop

查看:29
本文介绍了将 the_contents 附加到循环之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用以下php文件时,我希望代码:

When I call the following php file, I want the code to:

  1. 获取最新的博文
  2. 附加一些文字
  3. 保存附加的博文

以下代码在某种程度上有效,因为它会执行第 1 步和第 2 步,但不会将内容保存为附加内容.任何帮助表示赞赏!谢谢,wp 开发新手.

The following code somewhat works in-so-far-as it will do steps 1 and 2 but will not save the contents as appended. Any help is appreciated! Thanks, novice wp developer.

<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/blog/wp-load.php' );
$wp_did_header = true;

$args = array( 'numberposts' => 1 );
$recent_posts = get_posts( $args );

foreach($recent_posts as $post)
{
    $post->post_content .= '<br />Some text appended to Post';
    $post->post_content = add_filter('the_content', $post->post_content);
    return $post->post_content;
}
?>

推荐答案

你不需要使用过滤器,只需在帖子后显示文本

You don't need use filters, just display text after the post

  foreach ($recent_posts as $post) :
  setup_postdata($post);
  the_content();
  echo '<br />Some text appended to Post';
  endforeach;

这篇关于将 the_contents 附加到循环之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆