如何在自定义帖子中调出默认帖子标题

时间:2019-09-08 作者:KUNLE RICHARD

我想要什么

<div class=\'article-content\'>
在前端显示为文本,而不是调出原始文章标题

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;
}

1 个回复
SO网友:djboris

我没看到你关了门<div class=\'article-content\'> 要素这可能就是问题所在。而且,它是空的,里面没有div.

相关推荐

如何让`wp-list-table`显示我在Custom-Post中的`Custom-Fields`

一切都好吗<我需要wp-list-table 也要显示custom-fields 在每个custom-post 我有,但我不知道如何做到这一点,在这幅图中,它显示了带有字段的表格:Title, Author and Publication Date: 我想要的是能够选择custom-fields 将出现,例如以下示例Title, Carta, Naipe, Author, and Date of Publication: