0

我想给出我的标题<?php echo get_the_title(); ?>条件陈述。如果不是 HOMEPAGE 则显示它是什么 = <?php echo get_the_title(); ?>。如果主页显示THIS IS + <?php echo get_the_title(); ?>

所以语法应该是

<?php

$path = $_SERVER['REQUEST_URI'];
$page = basename($path);
$page = basename($path, '.php');

?>


<?php if($page == 'index') 
  {echo 'This is'. get_the_title();  }
   else 
   {echo get_the_title();}
?>

问题是我真的不知道在 wordpress 中我们是否使用相同的方式或更智能或更简单的方式。

哦,忘记了! 实际上,我的索引/主页不是真正的索引,它是名为“HOMEPAGE”的页面设置来自Reading Settings -> a static page, front page => HOMEPAGE

感谢您的任何建议。

4

2 回答 2

1

将您的代码放入functions.php

function title_edit($title){
    if(!is_front_page() || get_post_type() != 'page') return $title;
    $title = 'Home: '.$title;
    return $title;
}

add_filter('the_title','title_edit');
于 2013-03-23T09:50:33.717 回答
0

问题解决了感谢@silentboy

<?php if(is_front_page()) 
    echo 'This is'.get_the_title(); 
     else echo get_the_title(); ?>
于 2013-03-24T00:53:46.020 回答