Php 无法将wordpress图像标题和内容放置在单个贴子页面上
正在努力在自定义主题中获取帖子内容上方的单个帖子图像和标题。 我可以在图像下方获取图像标题,并在新div下方获取剩余内容吗 当前代码:Php 无法将wordpress图像标题和内容放置在单个贴子页面上,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,正在努力在自定义主题中获取帖子内容上方的单个帖子图像和标题。 我可以在图像下方获取图像标题,并在新div下方获取剩余内容吗 当前代码: <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <?php the_title( '<h3 class="title no-underline"
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h3 class="title no-underline">', '</h3>' ); ?>
</header>
<div class="entry-content news-item-copy">
<?php
$get_description = get_post(get_post_thumbnail_id())->post_excerpt;
the_post_thumbnail();
if(!empty($get_description)){//If description is not empty show the div
echo '<div class="image-captions">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>';
}
?>
<div class="news-sharing">
<a class="socialite twitter-share" href="" target="_blank" data-via="" data-text="New Website Launch — " data-url="" data-count="horizontal">Share on Twitter</a>
<a class="facebook-like socialite" data-href="" target="_blank" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false">Like on Facebook</a>
</div>
<?php the_excerpt(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'themeName' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
这适用于显示文章图像和摘录,但不显示带有标题的图像,也不显示文章全文
替换此:
<?php the_excerpt(); ?>
与:
再次返回包含图像的完整帖子内容。试试这个,只获取帖子对象及其值没有什么特别的。post_摘录也称为标题
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h3 class="title no-underline">', '</h3>' ); ?>
</header>
<div class="entry-content news-item-copy">
<?php
if(has_post_thumbnail())
{
the_post_thumbnail();
$thumbnail_id = get_post_thumbnail_id(get_the_ID());
$thumbnail_data = get_post($thumbnail_id);
$caption = $thumbnail_data->post_excerpt;
if(!empty($caption)){//If description is not empty show the div
echo '<div class="image-captions">' . $caption . '</div>';
}
}
?>
<div class="news-sharing">
<a class="socialite twitter-share" href="" target="_blank" data-via="" data-text="New Website Launch — " data-url="" data-count="horizontal">Share on Twitter</a>
<a class="facebook-like socialite" data-href="" target="_blank" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false">Like on Facebook</a>
</div>
<?php
echo the_content();
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'themeName' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
在此之后,您不需要将特色/缩略图图像添加到帖子内容中,它也不会再次出现在内容中。我希望这现在是有意义的。我建议在……开始时问你的问题。。。问题帖:如果我们需要搜索问题的实际内容,那么帮助那个人就更困难了。在获取图像/缩略图标题时,我能够找出问题的前半部分。替换为上面的新代码。仍在努力找出如何在新闻分享版块下获取帖子内容。谢谢。不幸的是,当我实现时,这似乎不起作用。我添加了一些新的php来获取图片和标题。
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h3 class="title no-underline">', '</h3>' ); ?>
</header>
<div class="entry-content news-item-copy">
<?php
if(has_post_thumbnail())
{
the_post_thumbnail();
$thumbnail_id = get_post_thumbnail_id(get_the_ID());
$thumbnail_data = get_post($thumbnail_id);
$caption = $thumbnail_data->post_excerpt;
if(!empty($caption)){//If description is not empty show the div
echo '<div class="image-captions">' . $caption . '</div>';
}
}
?>
<div class="news-sharing">
<a class="socialite twitter-share" href="" target="_blank" data-via="" data-text="New Website Launch — " data-url="" data-count="horizontal">Share on Twitter</a>
<a class="facebook-like socialite" data-href="" target="_blank" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false">Like on Facebook</a>
</div>
<?php
echo the_content();
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'themeName' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->