• ResolvedPlugin Contributor Babak Fakhamzadeh

    (@mastababa)


    How can I display a random name in the sidebar of my site? I’m thinking of a shortcode along the lines of [name-dictionary dic=’1′ name=’random’].

    Similarly, I would love to be able to include particular names in my site content. So, a shortcode like [name-dictionary dic=’1′ name=’somename’] or [name-dictionary dic=’1′ name=’12’] would work for that.

    Does this exist?

    If not, I’m assuming the dictionaries are added via a custom content type. What’s the content type? This, so that I can write my own shortcode for this.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Jeroen Peters

    (@jeroenpeters1986)

    Hi @mastababa ,

    at the moment those shortcodes do not exist. I could add it but at the moment I don’t have tons of time to develop.

    The plugin is ordened in an old-fashion way and I have to tell you it uses it’s own two tables, and not custom content types (for now).
    I’m sorry for this.

    Thank you for sharing your ideas! I might implement it in the future, but I don’t have the time in a short term. I do hope my answers helped so you could create your own.

    Kind regards,

    Jeroen Peters

    Plugin Contributor Babak Fakhamzadeh

    (@mastababa)

    Understood.

    On your next update, consider adding the following function to shortcode.php. It adds a shortcode to display a random name.

    Use like this: [namedirectory_random dir=”2″]

    function name_directory_show_random($attributes) {
        $dir = null;
        extract(shortcode_atts(
            array('dir' => '1'),
            $attributes
        ));
    	
        $name_filter = array();
        $directory = name_directory_get_directory_properties($dir);
        $names = name_directory_get_directory_names($directory, $name_filter);
        $num_names = count($names);
    
    	if ($num_names > 0) {
    		$entry = $names[array_rand($names)];
    
    	    ob_start();
    
    		echo '<div class="name_directory_random_name">';
            echo '<div class="name_directory_name_box">';
            echo '<a name="namedirectory_' . sanitize_html_class($entry['name']) . '"></a>';
            echo '<strong>' . htmlspecialchars($entry['name']) . '</strong>';
            if(! empty($directory['show_description']) && ! empty($entry['description']))
            {
                $print_description = html_entity_decode(stripslashes($entry['description']));
    
                /* This toggles the read more/less indicators, these need extra html */
                if(! empty($directory['nr_words_description']))
                {
                    $num_words = intval($directory['nr_words_description']);
                    $short_desc = name_directory_get_words($print_description, $num_words);
                    $print_description = str_replace($short_desc, "", $print_description);
                    if(! empty($print_description))
                    {
                        echo '<br /><div>
                          <input type="checkbox" class="name-directory-readmore-state" id="name-' . htmlspecialchars($entry['id']) . '" />
                          <span class="name-directory-readmore-wrap">' . $short_desc . ' <span class="name-directory-readmore-target">' . $print_description .'</span></span>
                          <label for="name-' . htmlspecialchars($entry['id']) . '" class="name-directory-readmore-trigger"></label>
                        </div>';
                    }
                    else
                    {
                        echo '<br /><div>' . $short_desc . '</div>';
                    }
    
                }
                else {
                    echo '<br /><div>' . $print_description . '</div>';
                }
            }
    		if(! empty($directory['show_submitter_name']) && ! empty($entry['submitted_by']))
    		{
    			echo "<small>" . __('Submitted by:', 'name-directory') . " " . $entry['submitted_by'] . "</small>";
    		}
            echo '</div>';
    		echo '</div>';
    
    		return ob_get_clean();
    	}
    	
    }
    add_shortcode('namedirectory_random', 'name_directory_show_random');

    I noticed in another thread you just became a parent. Happy parenting! ??

    Plugin Author Jeroen Peters

    (@jeroenpeters1986)

    Hi @mastababa ,

    thanks on the Congratulations and for the code. I will include it in v1.12, thank you!

    Kind regards,

    Jeroen Petes

    Plugin Contributor Babak Fakhamzadeh

    (@mastababa)

    You’re welcome ??

    Plugin Contributor Babak Fakhamzadeh

    (@mastababa)

    I see you pushed out a new release. I think I’m not the only one contributing to this release, right?

    You might want to consider adding the contributors to the list of “Contributors & Developers” at the bottom of the main plugin page.

    Plugin Author Jeroen Peters

    (@jeroenpeters1986)

    Hey @mastababa ,

    Thanks for the tip, I did put you Guys in the release notes, I have to check where i can add you and Marin for the contributers part.

    I Will take care of that ??

    Kind regards,

    Jeroen Peters

    Plugin Contributor Babak Fakhamzadeh

    (@mastababa)

    Cool!

    Plugin Author Jeroen Peters

    (@jeroenpeters1986)

    I have added you both, but your name does not seem to show up on my screen, your avatar does, so I am sure the name is spelled correctly.
    Did you do something in your profile?

    Plugin Contributor Babak Fakhamzadeh

    (@mastababa)

    Thanks!

    It’s a WordPress bug. My name also doesn’t show in the top right of this site when logged in. Even though my profile has the correct info.

    Plugin Contributor Babak Fakhamzadeh

    (@mastababa)

    How about that! This suddenly resolved itself, after, what, years!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Shortcode for showing a random name?’ is closed to new replies.