开发者

Highlighting tabs in CSS: Wordpress theme Development

开发者 https://www.devze.com 2023-03-31 10:23 出处:网络
I need your help on my test wordpress theme development self-training. I want to create highlighting tabs in css similar to http://www.countryqueenslandbookkeepers.com.au/ , I try made a similar in wo

I need your help on my test wordpress theme development self-training. I want to create highlighting tabs in css similar to http://www.countryqueenslandbookkeepers.com.au/ , I try made a similar in wordpress by getting the value of page_id in the URL and compare it to the post ID. if it is equal, then echo should be "selected" or else "default". It works fine , however, when I change the permalink something like www.mydomain/%postname%/ , it doesn't work anymore.

How could i get the value or how can I compare /%postname%/ so that I could echo "selected" to my link?

<?php 
        $all_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE
                post_type = 'page' AND 
                post_status = 'publish'
                ORDER by ID ASC");  
        foreach ($all_posts as $post):
    ?> 
        <li class="<?php 
                        if($post->ID == $_GET['page_id']){
  开发者_高级运维                          echo"selected";
                        }else{
                            echo "default";
                        }?>">
            <a href="<?php echo $post->guid; ?>"><?php echo $post->post_title; ?></a>
        </li>
    <?php endforeach; ?>    


Use get_permalink instead. You pass in the post id and the permalink is returned. Also check out wordpress.stackexchange.com. Wordpress codex questions like this are often answered better over there. Coding questions do better here.

     <?php 
     if(get_permalink($post->ID) == currentURL){
           echo"selected";
     }else{
        echo "default";
     }?>">


You'll want to use the CSS class .current-menu-item which is automatically applied to every active menu item. Modify your style.css accordingly and you'll achieve the highlighting effect. Please see the WordPress Codex on Dynamic Menu Highlighting.

0

精彩评论

暂无评论...
验证码 换一张
取 消