Php 如何从WordPress分类页面的内容中剥离嵌入式视频?
我有几篇帖子都嵌入了YouTube视频。我只希望视频显示在文章的完整版本上。在列出帖子的分类页面上,我不希望视频出现 以下是网站: 全文如下: 下面是我在functions.php中使用的一段代码,仅当文章的第一个图像列在类别页面上时,才从文章中删除它:Php 如何从WordPress分类页面的内容中剥离嵌入式视频?,php,wordpress,video,categories,Php,Wordpress,Video,Categories,我有几篇帖子都嵌入了YouTube视频。我只希望视频显示在文章的完整版本上。在列出帖子的分类页面上,我不希望视频出现 以下是网站: 全文如下: 下面是我在functions.php中使用的一段代码,仅当文章的第一个图像列在类别页面上时,才从文章中删除它: function remove_first_image ($content) { if (is_category()) { $content = preg_replace("/<img[^>]+\>/i", "", $cont
function remove_first_image ($content) {
if (is_category()) {
$content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
$content = preg_replace("/<object[^>]+>/i", "", $content, 1);
} return $content;
}
add_filter('the_content', 'remove_first_image');
另外,下面是我在index.php和category.php文件上使用的循环:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="votes" style="min-width:60px"><strong>VOTES:</strong><?php wdpv_vote(false); ?></div>
<div class="alignleft" style="max-width:590px">
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h2>
<div class="byline"><?php the_time('F jS, Y') ?> by <?php the_author() ?> in <?php the_category(', ') ?> <strong>:</strong> <?php comments_number( 'No Comments', '1 Comment', '% Comments' ); ?></div>
<div class="excerpt">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail(array(115,115));
}
?>
<?php the_content('Read more »'); ?>
</div>
<?php endwhile; ?>
<?php else : ?>
<h1>Not Found</h1>
<p><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
<?php endif; ?>
任何帮助都将不胜感激……我相信这是一个WordPress网站 如果是这样,您需要查看编辑主题模板文件,该文件负责在分类页面上显示文章预览,并删除文章中显示图像/视频的部分 不幸的是,不知道您使用的是什么主题,或者文件名叫什么,很难说清楚,但是要寻找一个包含单词home或categories的页面模板,或者从激活的主题文件夹中打开category.php,如果有,看看是否可以找到与此相关的内容,并对其进行注释,看看是否可以它修复了它 还可以尝试在自定义函数中添加以下内容:
$content = preg_replace("/<embed[^>]+>/i", "", $content, 1);
我相信这是一个WordPress网站 如果是这样,您需要查看编辑主题模板文件,该文件负责在分类页面上显示文章预览,并删除文章中显示图像/视频的部分 不幸的是,不知道您使用的是什么主题,或者文件名叫什么,很难说清楚,但是要寻找一个包含单词home或categories的页面模板,或者从激活的主题文件夹中打开category.php,如果有,看看是否可以找到与此相关的内容,并对其进行注释,看看是否可以它修复了它 还可以尝试在自定义函数中添加以下内容:
$content = preg_replace("/<embed[^>]+>/i", "", $content, 1);
这是一个自定义主题。我已经编辑了我的原始问题,上面,包括类别页面的post循环。您是否尝试使用$content=preg_replace/]+>/I,$content,1;要删除视频对象吗?我编辑了我的问题以显示更新的功能。不幸的是,视频仍在播放。辛西娅道歉。我的意思是嵌入而不是对象。请将对象替换为嵌入,然后重试。抱歉我实际上必须去掉嵌入和对象,然后它就工作了。谢谢这是一个自定义主题。我已经编辑了我的原始问题,上面,包括类别页面的post循环。您是否尝试使用$content=preg_replace/]+>/I,$content,1;要删除视频对象吗?我编辑了我的问题以显示更新的功能。不幸的是,视频仍在播放。辛西娅道歉。我的意思是嵌入而不是对象。请将对象替换为嵌入,然后重试。抱歉我实际上必须去掉嵌入和对象,然后它就工作了。谢谢