我在Wordpress上有一个网站。 我的子页面上显示了一个菜单。 一切都很完美。 我还有索引A,B,C等格式。 在我的CSS中,一切都是大写的。它适用于Chrome,Firefox,但不适用于Safari,我的菜单中的选项是小写的。 所以我需要在大写字母中输入我自己的页面...这不是我猜的最佳解决方案.... 所以我想添加一个PHP函数来大写我的post_title而不是使用CSS来做它。 我知道我可以使用“strtoupper”功能,但在这种情况下我不知道该使用它:
echo '<select name="" onchange="location = this.options[this.selectedIndex].value;">';
这是构建菜单的mu full php代码:
<div class="styled-select">
<?php
if(!$post->post_parent){
$children = get_pages(array(
'child_of' => $post->ID,
'post_type' => 'page',
'post_status' => 'publish',
'sort_order' => 'ASC',
'sort_column' => 'post_title',
));
}else{
$children = get_pages(array(
'child_of' => $post->post_parent,
'post_type' => 'page',
'post_status' => 'publish',
'sort_order' => 'ASC',
'sort_column' => 'post_title',
));
}
if ($children) {
echo '<select name="" onchange="location = this.options[this.selectedIndex].value;">';
echo '<option>'. 'A - Z' .'</option>';
function getInitials($name){
//split name using spaces
$words=explode(" ",$name);
$inits='';
//loop through array extracting initial letters
foreach($words as $word){
$inits = strtoupper(substr($word,0,1));
break;
}
return $inits;
}
$currval = "";
foreach($children as $child){
//print_r($child);
$permalink = get_permalink($child->ID);
$initial = getInitials($child->post_title);
if($initial!='' && $currval != $initial ) {
$currval = $initial;
echo '<optgroup label="'.$initial.'""></optgroup>';
}
echo '<option value="'.$permalink.'">'.$child->post_title.'</option>';
}
echo '</select>';
} ?>
<!-- FIN MENU DEROULANT A-Z -->
</div>
这是一个jsfiddle:http://jsfiddle.net/3LZEt/
如果有人可以帮助我的话! 非常感谢。
答案 0 :(得分:0)
显示的选项文本不应与您的重定向没有任何关系。
我是否正确理解重定向确实令您烦恼? 那你尝试过safari mobile吗?如果是这样,它不支持onchange,但onblur
echo '<select name="" onblur="location = this.options[this.selectedIndex].value;">';
但这打破了我认为的其他浏览器,因此需要为一个浏览器和非工作浏览器进行切换以换取另一个浏览器和onblur。
修改强> 请看这部分,你有你的帖子标题
foreach($children as $child){
//print_r($child);
$permalink = get_permalink($child->ID);
$initial = getInitials($child->post_title);
if($initial!='' && $currval != $initial ) {
$currval = $initial;
echo '<optgroup label="'.$initial.'""></optgroup>';
}
echo '<option value="'.$permalink.'">'.$child->post_title.'</option>';
}
所以,请改用
foreach($children as $child){
//print_r($child);
$permalink = get_permalink($child->ID);
$post_title = strtoupper($child->post_title);
$initial = getInitials($child->post_title);
if($initial!='' && $currval != $initial ) {
$currval = $initial;
echo '<optgroup label="'.$initial.'""></optgroup>';
}
echo '<option value="'.$permalink.'">'.$post_title.'</option>';
}