WordPress.org

Ready to get started?Download WordPress

Forums

Select widgets by page (4 posts)

  1. johnhennmacc
    Member
    Posted 3 years ago #

    How about building in the ability to specify the widgets you want to display on each page of your site from the dashboard? For example, I could see it being handy to display all widgets on the blog's front page and only a few of them on all the others. It would be very useful for the likes of WordPress.com and any other multi-site instances of WordPress that there may be where users cannot have access to theme code or upload themes of their own choosing.

  2. President McCheese
    Member
    Posted 3 years ago #

    Here's an idea I've used before -

    With a little JavaScript you could toggle visibility by using comment tags in the page content.

    You could use a comment tag like this in your page content -
    <!-- !widget-1 -->

    Then use js to toggle the visibility of widget-1 -

    p = $(this).html().split('!widget-1');
                    if(p[1]){
                      $('.widget-1').hide();
                    }

    You can create any number of tags which would toggle specific widgets.

    Perhaps one benefit to this method is that search engines would still index the widget content even if it's not visible.

    Just be sure you're not reading the tags from page visitor-submitted comments. :)

  3. President McCheese
    Member
    Posted 3 years ago #

    I made a jQuery plugin to do something like this. Except you can use any HTML tag's rel attribute to hold a list of object id's or class names, like this -
    Head:

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="jquery.jlvisi.js"></script>
    
    <script type="text/javascript">
    	jQuery(document).ready(function () {
        $('#visibility').jlvisi();
    });
    </script>

    Post or page content:
    <span id="visibility" rel="!.widget-1,!.widget-2,*.widget-3"></span>
    In this example, the span tag could be added to the post or page to control the visibility of the widgets listed in the rel attribute. The ! exclamation mark preceding a class name indicates the object will be hidden. The * asterisk preceding a class name indicates the object will be visible.

    You can get the plugin at my website http://jasonlau.biz/home/jquery/jlvisi-a-jquery-plugin.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags