我想为函数中的\\u内容添加\\u筛选器。我的主题的php。我添加了只显示echo的代码,但它表明我的过滤器没有应用。
function add_mod_hatom_data($content) {
// $t = get_the_modified_time(\'F jS, Y\');
//$author = get_the_author();
// $title = get_the_title();
//if(is_single()) {
echo \'perrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\';
// $content .= \'<div class="hatom-extra"><span class="entry-title">\'.$title.\'</span> was last modified: <span class="updated"> \'.
//$t.\'</span> by <span class="author vcard"><span class="fn">\'.$author.\'</span></span></div>\';
// }
return $content;
}
add_filter(\'the_content\', \'add_mod_hatom_data\');
我试着这样称呼它:
add_filter(\'the_content\', \'add_mod_hatom_data\', 99);
或将位置更改为位于功能顶部。php没有成功。
我是否需要启用某处add\\u过滤器,或者它被其他函数覆盖?注意:在我的单个帖子模板中,我有:
<?php get_header(); ?>
<div id="content" class="clearfix row">
<div id="main" class="col-sm-8 clearfix" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(\'clearfix\'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
<header>
<div class="page-header clip_content single-post">
<div class="page-header">
<h1 class="single-title-wg" itemprop="headline">
<?php $category = get_the_category();
if ($category[0]) {
echo \'<b>\'.$category[0]->cat_name.\' \'.$post->ID.\'</b>\';
}
?>
</h1>
<h4 class="single-title" itemprop="headline">
<p class="lead">
<?php the_title(); ?>
</p>
</h4>
</div>
<div class="item_footer">
</div>
<?php $category = get_the_category();
if ($category[0]) {?>
<p class="authorParagraph">
<?php echo \'<a href="\' . get_category_link($category[0]->term_id) . \'" class="clearfix">\' . $category[0]->cat_name . \'</a></p>\';
}
?>
</div>
</div>
</header> <!-- end article header -->
<footer>
<!-- <?php the_tags(\'<p class="tags"><span class="tags-title">\' . __("Tags","wpbootstrap") . \':</span> \', \' \', \'</p>\'); ?> -->
</footer> <!-- end article footer -->
</article> <!-- end article -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("Not Found", "wpbootstrap"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Sorry, but the requested resource was not found on this site.", "wpbootstrap"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- end #main -->
</div> <!-- end #content -->
<?php get_footer(); ?>
最合适的回答,由SO网友:Matt Royal 整理而成
单帖子模板的这一部分称为循环:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
在循环中,您需要调用以下内容:
<?php the_content(); ?>
将您的单个帖子模板替换为以下内容,然后查看它现在是否有效:
<?php get_header(); ?>
<div id="content" class="clearfix row">
<div id="main" class="col-sm-8 clearfix" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(\'clearfix\'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
<header>
<div class="page-header clip_content single-post">
<div class="page-header">
<h1 class="single-title-wg" itemprop="headline">
<?php $category = get_the_category();
if ($category[0]) {
echo \'<b>\'.$category[0]->cat_name.\' \'.$post->ID.\'</b>\';
}
?>
</h1>
<h4 class="single-title" itemprop="headline">
<p class="lead"> <?php the_title(); ?></p></h4>
<p><?php the_content(); ?></p>
</div>
<div class="item_footer">
</div>
<?php $category = get_the_category();
if ($category[0]) {?>
<p class="authorParagraph">
<?php echo \'<a href="\' . get_category_link($category[0]->term_id) . \'" class="clearfix">\' . $category[0]->cat_name . \'</a></p>\';
}
?>
</div>
</div>
</header> <!-- end article header -->
<footer>
<!-- <?php the_tags(\'<p class="tags"><span class="tags-title">\' . __("Tags","wpbootstrap") . \':</span> \', \' \', \'</p>\'); ?> -->
</footer> <!-- end article footer -->
</article> <!-- end article -->
<?php endwhile; ?>
<?php else : ?>
<article id="post-not-found">
<header>
<h1><?php _e("Not Found", "wpbootstrap"); ?></h1>
</header>
<section class="post_content">
<p><?php _e("Sorry, but the requested resource was not found on this site.", "wpbootstrap"); ?></p>
</section>
<footer>
</footer>
</article>
<?php endif; ?>
</div> <!-- end #main -->
</div> <!-- end #content -->
<?php get_footer(); ?>