开发者

Wordpress Sidebar Not Showing

开发者 https://www.devze.com 2023-04-12 03:09 出处:网络
Hi creating new theme in wordpress. Having prob with sidebar, it should display the main parent title then all the children.

Hi creating new theme in wordpress.

Having prob with sidebar, it should display the main parent title then all the children.

<?php if ( !function_exists('register_sidebar')|| !register_sidebar() ) : ?>
    <ul id="sidebar">
        <?php
        if($post->开发者_如何学C;post_parent){
            $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
            $title_heading = get_the_title($post->post_parent);
        } else {
            $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
            $title_heading = get_the_title($post->ID);
        }

        if($children) { ?>

        <li><h3><?php echo $title_heading; ?> </h3>
            <ul>
                <?php echo $children; ?>
            </ul></li>
        <?php } ?>
    </ul>
    <?php endif; // end primary widget area ?>

but its not displaying anything.

It shows the sidebar div in firebug so is displaying sidebar.

Its on localhost so cant give url.

All help appreciated

Cheers Joe


I can see one of two problems:

  1. You have a sidebar registered, which means the condition is passed and it's trying to use the widgetized sidebar; you do not have widgets in your sidebar so it is not showing anything. (in other words, if you have a sidebar, the above code will never display anything anyhow).

  2. You do not have a sidebar registered, so it's passing the condition. However, the next conditions are not passed because they're not met OR because the loop hasn't triggered yet and you do not have access to those variables.

Quick and cheap way to see if conditions are met is to simply echo out some plain text or markup just inside each condition:

...
if($post->post_parent){
   echo('Parent found');
...

(for example)

0

精彩评论

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

关注公众号