wordpress - 在自定义字段之后显示自定义帖子类型的 get_content
问题描述
我创建了自己的简码来显示来自自定义帖子类型的数据。我可以在我的页面上使用自定义值显示不同的汽车类型。但我的 CPT 还支持编辑器(WPBakery Page Builder),管理员可以在其中为每辆车添加/自定义额外内容。(附加信息)。
我的问题:
我想在自定义字段下方添加/显示编辑器的内容(=> the_content)。但是,一旦我输出“the_content”,它就会出现在每种类型汽车的页面顶部。我可以使用“get_the_content”在正确的位置('.$content.')显示数据,但它不会包含任何格式,也不会显示图片,而是输出整个 img-tag + 信息。
有没有办法解决这个问题?
先感谢您!
使用 the_content() 输出
使用 get_the_content() 输出
<?php
if(!defined('ABSPATH')){
exit;
}
add_shortcode('fahrzeuge', 'display_fahrzeuge');
function display_fahrzeuge($atts, $content = null) {
$output = '';
$args = array(
'post_type' => 'fahrzeuge',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'Fahrzeugtypen',
'field' => 'slug',
'terms' => 'kommandofahrzeuge')));
$output.= '';
$kommandofahrzeuge = new WP_Query( $args );
if( $kommandofahrzeuge->have_posts() ) :
while( $kommandofahrzeuge->have_posts() ) :
$kommandofahrzeuge->the_post();
$post_id = get_the_ID();
$taktischeBezeichnung = esc_html(get_post_meta($post_id,'ff_ried_fahrzeuge_taktischeBezeichnung', true));
$featured_img_url = get_the_post_thumbnail_url($post_id,'full');
$output.='
<div>'.$taktischeBezeichnung.'</div>
<img class="fahrzeugeFeaturedImage" src='.$featured_img_url.'></img>
<div>'.$content.'</div>
';
endwhile;
wp_reset_postdata();
else :
esc_html_e( 'Keine Fahrzeuge gefunden', 'text-domain' );
endif;
echo $output;
}
?>
解决方案
解决方案:
将此函数插入到functions.php中
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
显示格式化的内容:
$content = get_the_content_with_formatting();
echo $content;
来源:http ://www.web-templates.nu/2008/08/31/get_the_content-with-formatting/index.html
推荐阅读
- java - 如何防止我的 MongoDB 数据库中的递归?
- c - 在 C 中正确处理 128..255 个字符
- cuda - CUDA Thrust - 选择性复制或替换为常数值
- powershell - PowerShell如何将剪贴板设置为RTF文件内容
- python - Python 脚本在 Spyder 中运行,但在打包为 Pyinstaller .exe 时会崩溃(关闭时没有错误消息)
- javascript - JS如何获取两个相同字符串字符之间的子字符串
- date - 将一年中的数字星期转换为 hiveql 中的日期 (yyyy-mm-dd)
- python - 如何处理将 isbnlib.meta 与 pandas 一起应用返回的错误
- flutter - 在将 Container 包装到 SigleChildScrollView 时,UI 看起来很模糊?
- sql - 解析地址:模仿这 8 行 Perl 的 T-SQL 代码?