0

When creating a widget, WordPress puts a <div class="typewidget"> around the widget.

I want to remove these extra divs without editing the wp-includes/default-widgets.php file.

In my theme index.php file, I use:

<ul>
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('widgetname') ) : ?>
<?php endif; ?>
</ul>

Then, in the functions.php file:

register_sidebar(array(
'name' => 'widgetname',
'before_widget' => '<li>',
'after_widget'  => '</li>',
));

And this shows in the site:

 <ul>
    <li> 
        <div class="textwidget">
            <strong><a href="#">musica</a></strong> <a href="#">Lorem ipsum dolor sit amet dolor sit am.</a>
        </div>
    </li>
 </ul> 

Any ideas? Thanks.

4

3 回答 3

1

一个朋友刚刚帮我解决了这个问题。

加载 jQuery 后:

var cnt = $(".textwidget").contents()
$(".textwidget").replaceWith(cnt);

.textwidget额外 div 中的类在哪里。它根据 WordPress 中每种类型的小部件而有所不同。

于 2011-03-26T04:20:35.623 回答
0

something like the following might work.

var stuff_in_div = document.getElementById("typewidget").innerHTML;

stuff_in_div.parentNode.removeChild("typewidget");

and then if you give the < li > an id like "target", you could just shove stuff_in_div in there with:

document.getElementById("target").innerHTML = stuff_in_div;

Does this seem reasonable?

Andy

于 2011-03-26T01:15:25.637 回答
0

如何使用类似的东西:

var stuff = document.getElementsByTagName("div");

for (i=0, i<stuff.length, i++) {

    if (stuff[i].className=='typewidget') {

        var stuff_in_div = stuff[i].innerHTML;
        stuff[i].parentNode.innerHTML=stuff_in_div;

    }

}

似乎这可能有效。你怎么看?

安迪

于 2011-03-26T02:25:06.000 回答