admin管理员组

文章数量:1414621

anything i put after

<div class='article-content'>

displays as a text on the front end instead of calling up the original post title

add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$posts = get_field('show_post_in_content_part',$postID);  if( $posts ): 
$category_detail=get_the_category($postID);
foreach($category_detail as $cd){
         $cat=$cd->cat_name;
 }
        foreach( $posts as $post): setup_postdata($post);
        $img = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); 
        $link=get_the_permalink($post->ID);
            $cn = $post->post_excerpt;
            $contenta=implode(' ', array_slice(explode(' ', $cn), 0, 32));
            $contentm=implode(' ', array_slice(explode(' ', $cn), 0, 15));

            $ad_code = "<div class='article-block cf'>
                                            <div class='triangle-02'>
                                                <!--<img src='".$img."' alt=''>-->
                                            </div>

                                            <div class='article-content'>
                                                <h3><div class= 'article-title'></h3>
                                                <p class='desktop_view'>".$contenta."</p>
                                                <p class='mobile'>".$contentm."</p>
                                                <p><a href='".$link."' class='readmore'>read more..</a></p>
                                            </div>
                                            <div class='article-img'>
                                                <div class='img'>
                                                    <img src='".$img."'>
                                                    <div class='caption'>".$cat."</div>
                                                </div>
                                            </div>
                                        </div>";
         endforeach;  wp_reset_postdata();  endif;
        if ( is_single() && ! is_admin() ) {
            return prefix_insert_after_paragraph( $ad_code, 2, $content );
        }
        return $content;
}

anything i put after

<div class='article-content'>

displays as a text on the front end instead of calling up the original post title

add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$posts = get_field('show_post_in_content_part',$postID);  if( $posts ): 
$category_detail=get_the_category($postID);
foreach($category_detail as $cd){
         $cat=$cd->cat_name;
 }
        foreach( $posts as $post): setup_postdata($post);
        $img = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); 
        $link=get_the_permalink($post->ID);
            $cn = $post->post_excerpt;
            $contenta=implode(' ', array_slice(explode(' ', $cn), 0, 32));
            $contentm=implode(' ', array_slice(explode(' ', $cn), 0, 15));

            $ad_code = "<div class='article-block cf'>
                                            <div class='triangle-02'>
                                                <!--<img src='".$img."' alt=''>-->
                                            </div>

                                            <div class='article-content'>
                                                <h3><div class= 'article-title'></h3>
                                                <p class='desktop_view'>".$contenta."</p>
                                                <p class='mobile'>".$contentm."</p>
                                                <p><a href='".$link."' class='readmore'>read more..</a></p>
                                            </div>
                                            <div class='article-img'>
                                                <div class='img'>
                                                    <img src='".$img."'>
                                                    <div class='caption'>".$cat."</div>
                                                </div>
                                            </div>
                                        </div>";
         endforeach;  wp_reset_postdata();  endif;
        if ( is_single() && ! is_admin() ) {
            return prefix_insert_after_paragraph( $ad_code, 2, $content );
        }
        return $content;
}
Share Improve this question edited Sep 9, 2019 at 0:35 Jacob Peattie 44.2k10 gold badges50 silver badges64 bronze badges asked Sep 8, 2019 at 13:11 KUNLE RICHARDKUNLE RICHARD 1
Add a comment  | 

1 Answer 1

Reset to default 0

I don't see you closed your <div class='article-content'> element. That is probably the issue. Also, it is empty, there is nothing 'inside' that div.

本文标签: How do i call up default post title in custom posts