我的index.php页面中包含以下代码, 该代码可提取所有页面并对其进行更改。问题是我还没有使用the_content()来显示内容, 而是使用了echo $ page-> post_content()。我现在必须在页面中嵌入一个联系表7, 但是当我在这里阅读其他问题时, 如果没有the_content(), 则短代码将不起作用。
我的问题是如何在这里显示联系方式以及任何技巧。
$pages = get_pages($args);
foreach ($pages as $page){
// Override Homepage
if($page->ID == 5){
$page->post_content = file_get_contents(get_template_directory_uri().'/includes/homepage-override.php');
}
// Check if it is menu page
if($page->post_parent == 169){
$page->post_content = file_get_contents(get_template_directory_uri().'/includes/location-menu-page.php?location='.$page->post_title);
}
// Calling Gallery Images
if($page->ID == 23){
$page->post_content = file_get_contents(get_template_directory_uri().'/includes/gallery-page.php');
}
// Calling about page
//if($page->ID == 7 || $page->ID == 17 || $page->ID == 29){
if(has_post_thumbnail($page->ID)):
$image = wp_get_attachment_image_src( get_post_thumbnail_id($page->ID), 'single-post-thumbnail' );
$dom = new DOMDocument();
@$dom->loadHTML($page->post_content);
$imgs = $dom->getElementsByTagName("img");
foreach($imgs as $img){
$img->setAttribute( 'src' , $image[0] );
break;
//}
}
$page->post_content = $dom->saveHTML();
endif;
echo $page->post_content;
//the_content(); This is not working
}
#1
你可以将the_content过滤器应用于post_content:
<?php echo apply_filters('the_content', $page->post_content); ?>
do_shortcode()也可能是:
<?php echo do_shortcode($page->post_content); ?>
评论前必须登录!
注册