PHP/WordPress:覆盖foreach循环中的页面id

PHP/WordPress:覆盖foreach循环中的页面id,php,wordpress,Php,Wordpress,我有一个WordPress网站,目前它的代码设置为基于页面标题创建标题。书名为:室内房屋绘画、室外房屋绘画和商业绘画。我想覆盖标题以删除单词house。这是当前的代码: <?php // interior_painting: 18 // exterior_painting: 25 // other services: 36 $page_ids = array(18, 25, 36); $images = array('servicesInterior.jpg', 'servicesExte

我有一个WordPress网站,目前它的代码设置为基于页面标题创建标题。书名为:室内房屋绘画、室外房屋绘画和商业绘画。我想覆盖标题以删除单词house。这是当前的代码:

<?php
// interior_painting: 18
// exterior_painting: 25
// other services: 36
$page_ids = array(18, 25, 36);
$images = array('servicesInterior.jpg', 'servicesExterior.jpg', 'servicesOther.jpg');
foreach ($page_ids as $key => $page_id) {
    $page_post = get_post($page_id);
    $page_custom_key = 'home_page_info';
    $page_link = $page_post->post_name;
    $li_class = $page_id == 36 ? 'noMargin' : '';
    $title = $page_id == 18 ? 'Interior Painting' : $page_post->post_title . " ";
    $title = $page_id == 36 ? 'Commercial Projects' : $page_post->post_title . " ";
    $title = $page_id == 25 ? 'Exterior Painting' : $page_post->post_title . " ";


    echo '<li class="' . $li_class . '"> <a href="' . $page_link . '">';
    echo '<img class="alignright size-full wp-image-349" title="servicesInterior" src="/wp-content/uploads/2011/04/' . $images[$key] . '" alt="" width="200" height="95" /></a>';
    echo '<h2>' . $title . '</h2>';
    echo get_post_meta($page_id, $page_custom_key, true);
    echo '<a class="btn-find-more" href="' . $page_post->post_name . '">FIND OUT MORE</a></li>';
}

?>

输出为:内部房屋油漆、外部油漆、商业油漆。如何从内部房屋油漆中移除房屋?

只需使用preg_替换“house”| |“house”,/*可变页面标题位于*/

您可以尝试替换该行:

echo '<h2>' . $title . '</h2>';
比如说:

if (is_page('Interior House Painting')) { echo '<h2>Interior Painting</h2>'; } 
if (is_page('Exterior House Painting')) { echo '<h2>Exterior Painting</h2>'; } 
else { echo '<h2>' . $title. '</h2>'; }
尽管如此,我还是有点好奇,为什么你不愿意把这个词从标题中完全删除

另外:有人提到使用preg_替换。这也是完全可能的,但最好进行不区分大小写的搜索:

$title = trim(preg_replace('/house/i', '', $page_post->post_title));
$title = trim(preg_replace('/house/i', '', $page_post->post_title));