Improve Banners Shortcode

Hi guys,

I added some code to the Banners shortcode in order to be able to pull the image Title and Description. Maybe you can consider adding this in future versions? There’s probably a sexier way to make the title and description meta available but it works fine.

(edited)
$IXAPtitle = trim( $IXAP105['title'] );
$IXAPdetails = trim( $IXAP105['details'] );
...
if ( empty( $IXAPtitle ) ) {
$IXAP62 .= "$IXAPthumbtitle";
}
if ( empty( $IXAPdetails ) ) {
$IXAP62 .= "$IXAPthumbdesc";
}

Thank you!

Regards,
B

P.S : What’s with the “$IXAP—” or “$IXAPWO–” variable names?! It’s giving me headaches hehe…

4 Responses to Improve Banners Shortcode

  1. Bastien January 21, 2016 at 8:46 pm #

    Got it!


    // =============================================================================
    // Affiliates Enterprise - Add Banner Informations
    // =============================================================================
    add_filter( 'affiliates_banner_image_after', 'nh_custom_banner_content' );
    function nh_custom_banner_content( $bannerinfo ) {
    $posts = get_posts( array( 'numberposts' => -1, 'post_type' => 'affiliates_banner', 'post_status' => 'publish' ) );
    foreach( $posts as $post ) {
    if ( get_post_thumbnail_id( $post->ID ) || get_post_meta( $post->ID, 'url', true ) ) { $post_ids[] = $post->ID; }
    }
    foreach( $post_ids as $post_id ) {
    $IXAPthumbtitle = get_post(get_post_thumbnail_id($post_id))->post_title;
    $IXAPthumbdesc = get_post(get_post_thumbnail_id($post_id))->post_content;
    $bannerinfo = "$IXAPthumbtitle";
    $bannerinfo .= "$IXAPthumbdesc";
    }
    return $bannerinfo;
    }

    Should I wrap a conditional somewhere to avoid any fatal errors?

    Thank you!

    Regards,
    B

    • Kento January 22, 2016 at 12:42 pm #

      Hi Bastien,

      Thanks for following up with your solution. I didn’t have a chance to review it up to now (you have probably seen the latest release is out by now). I don’t see the need for a conditional here as you’re already hooking on the action and don’t use any API functions that would require specific resources to be present that wouldn’t be there already.

      Cheers

  2. Bastien January 21, 2016 at 8:36 pm #

    Hey Kento,

    That’s what I figured out, makes sense too.

    Alright I knew there was better way to achieve this. I’m not entirely sure how to use filters though, I’ve added this function :

    add_filter( 'affiliates_banner_image_after', 'nh_custom_banner_content' );
    function nh_custom_banner_content( $bannerinfo ) {
    global $post_id;
    if ($post_id='') {return;}
    $IXAPthumbtitle = get_post(get_post_thumbnail_id($post_id))->post_title;
    $IXAPthumbdesc = get_post(get_post_thumbnail_id($post_id))->post_content;
    $bannerinfo = "$IXAPthumbtitle";
    $bannerinfo .= "$IXAPthumbdesc";
    return $bannerinfo;
    }

    But I’m affraid this returns the $post_id returned is the one of the affiliate dashboard page, not the current banner post id. How would I retrieve that?

    Thank you!

    Regards,
    B

  3. Kento January 21, 2016 at 8:13 pm #

    Hi Bastien,

    You’re appending two strings $IXAPthumbtitle and $IXAPthumbdesc but you can achieve this rather by using the affiliates_banner_image_after filter which allows you to insert HTML right at the same place where you add those strings in your modified code.

    Thanks for the suggestion but we can’t add the suggested modification because the filters already cover such cases more appropriately and don’t depend on additional attributes passed to the shortcode.

    The odd variable naming is resultant from our code protection for premium and proprietary parts.

    Cheers

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share