• Resolved huskypup

    (@huskypup)


    Hi Paul,
    I’m really finding your plugin very useful.

    I’m using it to pull a list of information leaflets based on what they’re tagged and display them using display_item_callback in my functions.php

    The leaflets are tagged with ‘expired’ or ‘not-expired’ and won’t display if leaflet is missing the ‘not-expired’ tag. I have 50 odd pages that display leaflets based on the department or specialty and sometimes the leaflets expire before they are renewed.

    The only thing I haven’t been able to figure out is how to display a message if no leaflets are returned. I’m not experienced enough in php to know how to add a check in my functions.php

    I have

    function pdfs_mediatags($post_item)
    {
    $media_src = wp_get_attachment_url($post_item->ID);
    return '<tr><td><a href="'.$media_src.'" title="'.$post_item->post_title.' class="media-tag-list clearfix" id="media-tag-item-'.$post_item->ID.'">'.$post_item->post_title.'</a></td><td>'.mysql2date("j M Y", $post_item->post_date).'</td></tr>';

    I know this isn’t good practice, but I managed to edit your mediatags_shortcodes.php file like so, which gives me what I need, but obviously as you update your plugin, I’ll need to keep a track of this

    function mediatags_shortcode_handler($atts, $content=null, $tableid=null)
    {
    	global $mediatags;
    
    	if ((!isset($atts['return_type'])) || ($atts['return_type'] != "li"))
    		$atts['return_type'] = "li";
    
    	if (!isset($atts['after_list'])) {
    		if (isset($atts['before_list'])) {
    			if ($atts['before_list'] == "ul")
    				$atts['after_list'] = "</ul>";
    			else if ($atts['before_list'] == "ol")
    				$atts['after_list'] = "</ol>";
    		} else {
    			$atts['after_list'] = "</ul>";
    		}
    	}
    
    	if (!isset($atts['before_list'])) {
    		$atts['before_list'] = "<ul>";
    	}
    
    	if (!isset($atts['error_message'])) {
    		$atts['error_message'] = "";
    	}
    
    	if ((!isset($atts['display_item_callback'])) || (strlen($atts['display_item_callback']) == 0))
    		$atts['display_item_callback'] = 'default_item_callback';
    
    //	if (isset($atts['post_parent'])) {
    //		if (($atts['post_parent'] == "this") || ($atts['post_parent'] == "self")) {
    //			$atts['post_parent'] = $post->ID;
    //		}
    //	}
    	$atts['call_source'] = "shortcode";
    
    	//echo "atts<pre>"; print_r($atts); echo "</pre>";
    
    	if (!is_object($mediatags))
    		$mediatags = new MediaTags();
    
    	$output = $mediatags->get_attachments_by_media_tags($atts);
    	if ($output)
    	{
    		if (isset($atts['before_list']))
    		{
    			$output = $atts['before_list'] . $output;
    		}
    
    		if (isset($atts['after_list']))
    		{
    			$output = $output .$atts['after_list'];
    		}
    	}
    	else {
    		$output = $output .$atts['error_message'];
    	}
    	return $output;
    
    }

    Is there a way of doing this with hacking your code?

    Many thanks
    Huseyin

    https://www.ads-software.com/plugins/media-tags/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Paul Menard

    (@pmenard)

    @huskypup,

    I agree the plugin probably needs to handle some ‘items not found logic’. My guess it you are using the shortcode meths, correct? In that case there it not a way within the shortcode to handle the case.

    Thread Starter huskypup

    (@huskypup)

    Thanks for the reply Paul.

    Yes, I had to add extra code to your mediatags_shortcodes.php and add an extra option of ‘error_message’ to the shortcode.

    Do you think this is something you’ll factor in future versions?

    Plugin Author Paul Menard

    (@pmenard)

    @huskypup,

    Yes, That is my thought. Will look at adding similar logic into the next release. Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Message if no items are returns’ is closed to new replies.