Exemple #1
0
/**
 * nggShowRelatedImages() - return related images based on category or tags
 * 
 * @access public 
 * @param string $type could be 'tags' or 'category'
 * @param integer $maxImages of images
 * @return the content
 */
function nggShowRelatedImages($type = '', $maxImages = 0)
{
    $ngg_options = nggGallery::get_option('ngg_options');
    if ($type == '') {
        $type = $ngg_options['appendType'];
        $maxImages = $ngg_options['maxImages'];
    }
    $sluglist = array();
    switch ($type) {
        case 'tags':
            if (function_exists('get_the_tags')) {
                $taglist = get_the_tags();
                if (is_array($taglist)) {
                    foreach ($taglist as $tag) {
                        $sluglist[] = $tag->slug;
                    }
                }
            }
            break;
        case 'category':
            $catlist = get_the_category();
            if (is_array($catlist)) {
                foreach ($catlist as $cat) {
                    $sluglist[] = $cat->category_nicename;
                }
            }
            break;
    }
    $sluglist = implode(',', $sluglist);
    $out = nggShowRelatedGallery($sluglist, $maxImages);
    return $out;
}
Exemple #2
0
/**
 * nggShowRelatedImages() - return related images based on category or tags
 *
 * @access public
 * @param string $type could be 'tags' or 'category'
 * @param integer $maxImages of images
 * @return related gallery output or empty string if not tags/categories
 * 20150309: fix: error when no tags in site.
 * Few simplifications
 */
function nggShowRelatedImages($type = '', $maxImages = 0)
{
    $ngg_options = nggGallery::get_option('ngg_options');
    if ($type == '') {
        $type = $ngg_options['appendType'];
        $maxImages = $ngg_options['maxImages'];
    }
    $sluglist = array();
    switch ($type) {
        case 'tags':
            $taglist = get_the_tags();
            //Return array of tag objects, false on failure or empty
            //This is a tag list for posts non Nextcellent tag lists.
            if (!$taglist) {
                return "";
            }
            foreach ($taglist as $tag) {
                $sluglist[] = $tag->slug;
            }
            break;
        case 'category':
            $catlist = get_the_category();
            //return array (empty if no categories)
            if (empty($catlist)) {
                return "";
            }
            foreach ($catlist as $cat) {
                $sluglist[] = $cat->category_nicename;
            }
            break;
    }
    $sluglist = implode(',', $sluglist);
    $out = nggShowRelatedGallery($sluglist, $maxImages);
    return $out;
}