在内容功能与其他内容发生冲突后发布图片库

时间:2021-03-18 作者:Sander1020

因此,我创建了一个包含帖子的博客,并使用此代码在帖子内容下显示了一个快捷码库。

问题是;“所有帖子”;页面中没有帖子。我认为这是因为我使用的$content变量。

因此,我使用is\\u single()只在单个贴子页面中执行add\\u content\\u after函数。但现在没有画廊显示。

有人知道我如何解决这个问题吗?谢谢

功能。php:

if ( is_single() ) {
    add_filter(\'the_content\', \'add_content_after\');

      function add_content_after($content) {

        global $post;

            if ( $post->post_status == \'publish\' ) {
            $attachments = get_posts( array(
                \'post_type\' => \'attachment\',
                \'posts_per_page\' => -1,
                \'post_parent\' => $post->ID,
                \'exclude\'     => get_post_thumbnail_id()
            ) );

            if ( $attachments ) {
                $atts = array();
                foreach ( $attachments as $attachment ) {
                    $class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type );
                    $thumbimg = wp_get_attachment_link( $attachment->ID, \'thumbnail-size\', true );

                    $atts[] = $attachment->ID;                                  
                }                                                           
                    $shortcode =  do_shortcode(\'[av_gallery ids="\' . implode(",", $atts) . \'" type="slideshow" preview_size="large" crop_big_preview_thumbnail="avia-gallery-big-crop-thumb" thumb_size="portfolio" columns="4" imagelink="lightbox" lazyload="avia_lazyload" av_uid="av-jgesnq4m" custom_class="av-gallery-style-"]\');

                $fullcontent = $content . $shortcode;

                return $fullcontent;

            }
        } 
    }
}

1 个回复
最合适的回答,由SO网友:Nour Edin Al-Habal 整理而成

移动is_single() 功能内部的条件,以及you have to return 如果不满足条件,则为原始内容。

您的代码如下所示:

add_filter(\'the_content\', \'add_content_after\');

function add_content_after($content) {
    global $post;
    
    if ( is_single() ) {
        if ( $post->post_status == \'publish\' ) {
            $attachments = get_posts( array(
                \'post_type\' => \'attachment\',
                \'posts_per_page\' => -1,
                \'post_parent\' => $post->ID,
                \'exclude\'     => get_post_thumbnail_id()
            ) );

            if ( !empty($attachments) ) {
                $atts = array();
                foreach ( $attachments as $attachment ) {
                    $class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type );
                    $thumbimg = wp_get_attachment_link( $attachment->ID, \'thumbnail-size\', true );

                    $atts[] = $attachment->ID;                                  
                }                                                           
                    $shortcode =  do_shortcode(\'[av_gallery ids="\' . implode(",", $atts) . \'" type="slideshow" preview_size="large" crop_big_preview_thumbnail="avia-gallery-big-crop-thumb" thumb_size="portfolio" columns="4" imagelink="lightbox" lazyload="avia_lazyload" av_uid="av-jgesnq4m" custom_class="av-gallery-style-"]\');

                $fullcontent = $content . $shortcode;

                return $fullcontent;

            }
        } 
    }
    
    return $content;
}

相关推荐

自定义“The_Posts_Pagination”并将列表放入div

Hello everybody, 我需要有关自定义wordpress分页的帮助。我想得到这个:这就是我所做的:在函数中。php,我添加了以下代码:function wp_custom_pagination($args = [], $class = \'pagination\') { if ($GLOBALS[\'wp_query\']->max_num_pages <= 1) return; $args = wp_parse_args( $args,