Php 在wordpress博客外显示wordpress文章的某些部分
我在我的自定义网站上有wordpress博客,我正在根据下面的标签将wordpress博客中的一些帖子显示到我的网站上Php 在wordpress博客外显示wordpress文章的某些部分,php,wordpress,Php,Wordpress,我在我的自定义网站上有wordpress博客,我正在根据下面的标签将wordpress博客中的一些帖子显示到我的网站上 require('../news/wp-blog-header.php'); $query = new WP_Query('tag=Dalaman'); if ($query->have_posts()):
require('../news/wp-blog-header.php');
$query = new WP_Query('tag=Dalaman');
if ($query->have_posts()):
while ($query->have_posts()) : $query->the_post();
?>
<h3> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p><?php the_content();?></p>
<?php
endwhile;
endif;
require('../news/wp blog header.php');
$query=new WP_query('tag=Dalaman');
如果($query->have_posts()):
而($query->have_posts()):$query->the_post();
?>
我建议你按照文章所说的去做,并在断点处插入一个
,这比去掉任意数量的字符更安全,因为这样可能会破坏html标记
如果你不关心那件事,那么
<?php the_content(); ?>
做
您可以像下面这样做
$limit = 55;
$content = explode(' ', get_the_content(), $limit);
if (count($content) >= $limit) {
array_pop($content);
$content = implode(" ", $content) . '...';
} else {
$content = implode(" ", $content);
}
$content = preg_replace('/\[.+\]/', '', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
我还从其他cutom博客中导入了所有帖子,所以帖子没有
,我会修改所有帖子,因为它们的数量超过了2000,所以我必须这样做,我不知道为什么这样“不起作用”?你有错误吗,你有没有得到一个不想要的结果?它给了我一个不想要的结果:-(你得到了哪个结果?来吧,有人为你写了一个答案,请给出一些合理的反馈,说明它是如何工作的。他们还需要如何改进答案?顺便说一句Cakephp有很好的truncate()
函数的字符串实用程序。它确实观察HTML标记,并且可能很容易在其他地方使用。
$limit = 55;
$content = explode(' ', get_the_content(), $limit);
if (count($content) >= $limit) {
array_pop($content);
$content = implode(" ", $content) . '...';
} else {
$content = implode(" ", $content);
}
$content = preg_replace('/\[.+\]/', '', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;