Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在帖子内容中插入特色图片_Php_Wordpress - Fatal编程技术网

Php 在帖子内容中插入特色图片

Php 在帖子内容中插入特色图片,php,wordpress,Php,Wordpress,我正在为我的网站使用wordpress主题,我正在尝试修改php,以便在文章内容中显示特色图像,而不是在文章之前或之后(文章顶部或底部) 以下是原始代码: <?php if ( ( has_post_thumbnail( $post_id ) || '' != get_post_meta( $post_id, 'Thumbnail', true ) ) && 'on' == et_get_option( 'origin_thumbnails' ) ) { ?>

我正在为我的网站使用wordpress主题,我正在尝试修改php,以便在文章内容中显示特色图像,而不是在文章之前或之后(文章顶部或底部)

以下是原始代码:

<?php if ( ( has_post_thumbnail( $post_id ) || '' != get_post_meta( $post_id, 'Thumbnail', true ) ) && 'on' == et_get_option( 'origin_thumbnails' ) ) { ?>
    <div class="post-thumbnail">
    <?php
        if ( has_post_thumbnail( $post_id ) ) the_post_thumbnail( 'full' );
        else printf( '<img src="%1$s" alt="%2$s" />', esc_attr( get_post_meta( $post_id, 'Thumbnail', true ) ), the_title_attribute( array( 'echo' => 0 ) ) );
    ?>
    </div>  <!-- end .post-thumbnail -->
<?php } ?>

    <?php the_content(); ?>

以下是我如何在我的孩子主题中调整它:

<?php the_content(); ?>

    <?php if ( ( has_post_thumbnail( $post_id ) || '' != get_post_meta( $post_id, 'Thumbnail', true ) ) && 'on' == et_get_option( 'origin_thumbnails' ) ) { ?>
    <div class="post-thumbnail">
    <?php
        if ( has_post_thumbnail( $post_id ) ) the_post_thumbnail( 'full' );
        else printf( '<img src="%1$s" alt="%2$s" />', esc_attr( get_post_meta( $post_id, 'Thumbnail', true ) ), the_title_attribute( array( 'echo' => 0 ) ) );
    ?>
    </div>

我对php不是很精通,所完成的只是将特色图片移动到帖子的底部:-/。我在我的主题论坛上发了帖子,收到了下面的代码,但似乎什么都没做

add_filter( 'the_content', insert_featured_image, 20 );

function insert_featured_image( $content ) {
$content = preg_replace( "/<\/p>/", "</p>" . get_the_post_thumbnail($post->ID, 'post-single'), $content, 1 );
return $content;
}
add_filter('the_content',insert_characterized_image,20);
函数插入功能图像($content){
$content=preg\u replace(“//”,“

”。获取\u post\u缩略图($post->ID,'post single'),$content,1); 返回$content; }
谁能给我指出正确的方向吗


蒂亚

试图将特色图像移动到内容中的原因是什么?Wordpress codex给出了以下示例:

// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
    the_post_thumbnail();
} 
the_content();
基本上,是“发布”缩略图();将显示选定为特色图像的图像,而_content();只是显示为该帖子或页面输入的所见即所得


如果您试图这样做,使其与设计或布局相匹配,您可能需要考虑将添加标记和样式应用于此区域。如果你需要特色图片前后的文本,你应该查看自定义字段。

如你所述,我希望在特色图片前后都有文本,这样访问者在帖子中看到的第一件事就不是他们首先点击的图片。如何使用自定义字段实现这一点?我不希望添加额外的图像,这将需要一个自定义字段。我希望现有的特色形象被放置到内容。请原谅我的无知,谢谢你的回复。我听说了一个叫做高级自定义字段的插件的好消息。从本质上讲,您可以通过插件的仪表板UI设置字段及其逻辑,然后在模板文件中有类似的内容:_content();如果(has_post_缩略图()){the_post_缩略图()}the_字段('extra-content');谢谢我需要将帖子内容添加到自定义字段还是使用默认的WP内容编辑器?我试图简化我的流程,而不是添加任何额外的步骤。