WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic Widgets
[resolved] Pods support in dynamic widgets? (12 posts)

  1. tommynz
    Member
    Posted 1 year ago #

    Hi

    The description for Dynamic Widgets says that it has support for Pods pages. I cannot see this anywhere, can you please explain how I can exclude a widget from my pods pages?

    Thanks
    tommynz

    http://wordpress.org/extend/plugins/dynamic-widgets/

  2. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    To get all available Pod Pages when Pods is active:

    if ( function_exists( 'is_pod_page' ) ) { // Check to see if Pod Pages are activated
        $pod_pages = pods_api()->load_pages();
    
        foreach ( $pod_pages as $pod_page ) {
            // display $pod_page[ 'name' ]
            // id is $pod_page[ 'id' ]
        }
    }

    To get the name from an ID, you can use:

    if ( function_exists( 'is_pod_page' ) ) {
        $pod_page = pods_api()->load_page( array( 'id' => $id ) );
    
        if ( !empty( $pod_page ) )
            $pod_page_name = $pod_page[ 'name' ];
    }

    Then to detect whether or not to show the widget:

    if ( function_exists( 'is_pod_page' ) ) {
        if ( is_pod_page( $pod_page_name ) ) {
            // show widget
        }
    }

    I'm adding the ability to pass the ID to is_pod_page in Pods 2.0.5, due out later this week.

  3. Qurl
    Member
    Plugin Author

    Posted 1 year ago #

    You should see a Pods section somewhere at the bottom of the DW widget options. Is that available to you?

  4. tommynz
    Member
    Posted 1 year ago #

    Hi Qurl

    No I do not have a Pods section. I see the following sections:
    Role
    Date
    Days
    Weeks
    Browser
    Templates
    URL
    Posts Page
    Single Posts
    Attachments
    Pages
    Author pages
    Category Pages
    Tag Pages
    Archive Pages
    Error Page
    Search Page
    Picture tag archive

    I am using Dynamic Widgets v1.5.3, it has (FILTER) after the version on the widget options page, and I am using Pods v2.0.4.1

  5. Qurl
    Member
    Plugin Author

    Posted 1 year ago #

    Ok, I have to look into Pods v2.0.4.1. I think something has changed along the way in Pods which makes DW not detecting Pods anymore.

  6. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    I'll check the DW code too to see if I can help you.

  7. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    Oh I see now, you did a custom SQL query instead of using the API. Use the API calls given in this thread instead and it should work with Pods 2.0

    For 1.x compatible code that works with 2.0, try this:

    if ( function_exists( 'is_pod_page' ) ) { // Check to see if Pod Pages are activated
        if ( function_exists( 'pods_api' ) )
            $pod_pages = pods_api()->load_pages();
        else
            $pod_pages = $GLOBALS[ 'wpdb' ]->get_results( "SELECT <code>id</code>, <code>uri</code> FROM <code>&quot; . $GLOBALS[ 'wpdb' ]->prefix . &quot;pod_pages</code>", ARRAY_A );
    
        foreach ( $pod_pages as $pod_page ) {
            // display $pod_page[ 'name' ], Pods 1.x uses $pod_page[ 'uri' ]
            // id is $pod_page[ 'id' ]
        }
    }
    if ( function_exists( 'is_pod_page' ) ) {
        if ( function_exists( 'pods_api' ) )
            $api = pods_api();
        else
            $api = new PodAPI();
    
        $pod_page = $api->load_page( array( 'id' => $id ) );
    
        if ( !empty( $pod_page ) ) {
            if ( function_exists( 'pods_api' ) )
                $pod_page_name = $pod_page[ 'name' ];
            else
                $pod_page_name = $pod_page[ 'uri' ];
        }
    }
  8. Qurl
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Scott,

    DW checks for the existence of the constant PODS_VERSION_FULL. When that exists, it assumes Pods is available.

    Pods module is in ./mods/pods_module.php
    The worker (script that takes care of acting upon the rules) has a pods section starting at line 761

  9. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    Check for defined( 'PODS_DIR' ) instead.

  10. Qurl
    Member
    Plugin Author

    Posted 1 year ago #

    Ah, right Scott. Thanks for that!

  11. Qurl
    Member
    Plugin Author

    Posted 1 year ago #

    Following the advice from Scott -thank you very much!- I have implemented the code into Dynamic Widgets development version 1.5.3.2. Please note it's not fully tested, but I assume Scott knows where he is talking about. ;)

    http://downloads.wordpress.org/plugin/dynamic-widgets.zip

  12. Scott Kingsley Clark
    Member
    Posted 1 year ago #

    Code looks solid to me, good job!

    I haven't actually tested it though, but you covered everything I'd thing would be necessary.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic