简体   繁体   English

引导选项卡PHP代码阻止活动选项卡更改-Wordpress

[英]Bootstrap Tabs PHP code blocking active tab change - Wordpress

I'm working on a navigation menu for my wordpress template, i'm using bootstrap 3 tabs in the header, but when i call function get_permalink( $page_name_id ) for <a href =""> tags in the <li> elements tabs getting stuck, but when I remove php code tabs are working. 我正在为我的wordpress模板创建导航菜单,正在使用标题中的bootstrap 3选项卡,但是当我为<li>元素选项卡中的<a href ="">标签调用函数get_permalink($ page_name_id)时被卡住,但是当我删除php代码时,标签会起作用。

My question is how I can get this tabs changing when I click on them and PHP code could return link of selected page? 我的问题是,当我单击它们时如何更改这些选项卡,而PHP代码可以返回所选页面的链接?

Here is code from header : 这是标题中的代码:

<ul class="nav nav-tabs" id="myTab" style = "font-size:12px;">
    <li class="active tab"><a href = "<?php echo wt_get_ID_by_page_name('home'); ?>" data-toggle="tab" >Home</a></li>
    <li class="tab"><a href = "<?php echo wt_get_ID_by_page_name('about'); ?>" data-toggle="tab" >About</a></li>
    <li class="tab"><a href = "<?php echo wt_get_ID_by_page_name('products'); ?>" data-toggle="tab" >Products</a></li>
    <li class="tab"><a href = "<?php echo wt_get_ID_by_page_name('contact'); ?>" data-toggle="tab" >Contact</a></li>
</ul>

function wt_get_ID_by_page_name it's hard coded function get_permalink by page_name_id, it returns just permalink by page name. 函数wt_get_ID_by_page_name是通过page_name_id硬编码的函数get_permalink,它仅按页面名称返回永久链接。

here is code : 这是代码:

function wt_get_ID_by_page_name($page_name)
{
    global $wpdb;
    $page_name_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."'");
    return $permalink = get_permalink( $page_name_id );
}

So, if you need PHP to select the active tab, you need to do some checking and decide whether or not to put the active class into the LI, similar (but not necessarily exactly) like the following: 因此,如果需要PHP选择活动选项卡,则需要进行一些检查并确定是否将活动类放入LI中,类似(但不一定完全)如下:

$url = $_SERVER['REQUEST_URI']; ?>

<li class='tab<?php echo $url == echo wt_get_ID_by_page_name('home') 
    ? ' active' : '' ?>'>...

If I misunderstood your question, let me know. 如果我误解了您的问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM