从函数中设置的帖子的动态内容中排除页面.WP


Excluding pages from dynamic content for posts set in functions.WP

在stackoverflow上非常有用的人的帮助下,我成功地为我的网站中使用的所有帖子添加了一个自定义的动态描述。我现在的问题是,当打开我的一个页面时,我不会得到页面内容,而是只用于帖子的动态描述。

我在functions.php中添加的用于生成动态描述的代码如下:

function add_after_post_content($content) {
global $post;
if(!is_feed() && !is_home() && is_singular() && is_main_query()) {
    $post_categories = wp_get_post_categories( $post->ID );
    $cats = array();
    foreach($post_categories as $c){
        $cat = get_category( $c );
        $cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
    }
    $content = '<h2>About the wallpaper:</h2><br />The <strong>'. $post->post_title . ' wallpaper</strong> is a high quality and high resolution wallpaper that has been posted in the <strong>';
        foreach($cats as $c){
           $content .= $c['name'];
        }
        $content .= '</strong> category by <strong>Free Wallpapers</strong> on '. $post->post_date . '.';
    }
    return $content;
}
add_filter('the_content', 'add_after_post_content');

现在的问题是,我在帖子页面上发现,例如版权页面,使用的是动态内容,而不是wordpress管理中设置的内容。

Copyright Policy and Usage Rights
About the wallpaper:
The Copyright Policy and Usage Rights wallpaper is a high quality and high resolution wallpaper that has been posted in the category by Free Wallpapers on 2014-05-14 20:56:29. 

我想继续在我的帖子中使用动态内容,同时将页面排除在显示之外。如果能在这方面提供任何帮助,我将不胜感激。

向致以最诚挚的问候

您想要使用is_singular函数。现在你想这样定义你的内容:

function add_after_post_content($content) {
    global $post;
    if(!is_feed() && !is_home() && is_singular('post') && is_main_query()) {
        $post_categories = wp_get_post_categories( $post->ID );
        $cats = array();
        foreach($post_categories as $c){
            $cat = get_category( $c );
            $cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
        }
        $content = '<h2>About the wallpaper:</h2><br />The <strong>'. $post->post_title . ' wallpaper</strong> is a high quality and high resolution wallpaper that has been posted in the <strong>';
        foreach($cats as $c){
            $content .= $c['name'];
        }
        $content .= '</strong> category by <strong>Free Wallpapers</strong> on '. $post->post_date . '.';
    }
    return $content;
}
add_filter('the_content', 'add_after_post_content');