WordPress.org

Ready to get started?Download WordPress

Forums

TooltipGlossary
Modification (enhancement?) (7 posts)

  1. vivahume
    Member
    Posted 3 years ago #

    Hey Thanx for the great plugin!!!

    I was having some problems with glossary terms that had a \n (new line) character in the definition, this crashed the tooltip. I made a few mods that others may find useful so I thought I'd post them.

    The jist of it is you can use excerpts to generate a short tooltip and then have a much more elaborate definition on your glossary page (with all kinds of fancy formatting).

    Only takes a few small changes... All Changes are in glossary.php

    #1. Enable the use of excerpts in the editor [line 48]:

    'supports' => array('title','editor','author','excerpt'));

    #2. Use the excerpt by default if it exists, if not, check the content for \n, replace if necessary, then shorten it up if it's too long. [around line 95].

    original:

    if (get_option('red_glossaryTooltip') == 1) {
    	$link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . addslashes($glossary_item->post_content) . '\');" onmouseout="tooltip.hide();">$1</a>';

    change to:

    if (get_option('red_glossaryTooltip') == 1) {
            /* new */
    	if(!empty($glossary_item->post_excerpt)){
    		$tip = $glossary_item->post_excerpt;
    	}elseif(preg_match('/\n+/', $glossary_item->post_content)){
    		$tip = preg_replace('/\n/', '<br/>', $glossary_item->post_content);
    	}else{
    		$tip = $glossary_item->post_content;
    	}
    
    	if (str_word_count($tip) > 50) $tip = implode(' ',array_slice(str_word_count($tip,1),0,50)).'...';
    
    	$link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . addslashes($tip) . '\');" onmouseout="tooltip.hide();">$1</a>';
    	/* end new */

    Thanx again!

    http://wordpress.org/extend/plugins/tooltipglossary/

  2. vivahume
    Member
    Posted 3 years ago #

    Oh you can also to the same for the gallery page...

  3. vivahume
    Member
    Posted 3 years ago #

    Ok, one last thing, if you want to juice up your gallery page you can use this to replace the function red_glossary_createList($content) [around line 133]:

    function red_glossary_createList($content){
    $glossaryPageID = get_option('red_glossaryID');
    if (is_numeric($glossaryPageID) && is_page($glossaryPageID)){
    	$glossary_index = get_children(array(
    		'post_type'		=> 'glossary',
    		'post_status'	=> 'publish',
    		'orderby'		=> 'title',
    		'order'			=> 'ASC',
    		));
    	if ($glossary_index){
    		$list .= '<div id="glossaryList">';
    		//style links based on option
    		if (get_option('red_glossaryDiffLinkClass') == 1) {
    			$glossary_style = 'glossaryLinkMain';
    		}
    		else {
    			$glossary_style = 'glossaryLink';
    		}
    
    		$alpha_link_list = '<div class="glossaryIndex">';
    		$curr_letter = '';
    		$alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
    		$check_letter = reset($alphabet);
    		foreach($glossary_index as $glossary_item){
    			$letter = strtoupper(substr($glossary_item->post_title,0,1));
    			if($letter !== $curr_letter){
    				$curr_letter = $letter;
    				while(($curr_letter !== $check_letter) && $check_letter){
    					$alpha_link_list .= ' '.$check_letter.' ';
    					$check_letter = next($alphabet);
    				}
    				$list .= '<div class="glossaryIndexAnchor"><a name="'.$letter.'">'.$letter.'</a></div>';
    				$alpha_link_list .= ' <a href="#'.$letter.'" class="glossaryIndexLink">'.$letter.'</a> ';
    				$check_letter = next($alphabet);
    			}
    
    			if(!empty($glossary_item->post_excerpt)){
    				$excerpt = $glossary_item->post_excerpt . '... [<a href="' . get_permalink($glossary_item) . '">more</a>]';
    			}else{
    				$excerpt = $glossary_item->post_content;
    			}
    
    			if (str_word_count($excerpt) > 25) $excerpt = implode(' ',array_slice(str_word_count($excerpt,1),0,25)).' ... [<a href="' . get_permalink($glossary_item) . '">more</a>]';
    			$list .= '<div class="glossaryTerm"><a class="' . $glossary_style . '" href="' . get_permalink($glossary_item) . '">'. $glossary_item->post_title . '</a> - '.$excerpt.'</div>';
    
    		}
    		//finish of the alphabet
    		if($check_letter){
    			while($check_letter){
    				$alpha_link_list .= ' '.$check_letter.' ';
    				$check_letter = next($alphabet);
    			}
    		}
    		$list .= '</div>';
    		$alpha_link_list .= '</div>';
    		}
    	}
    return $content.$alpha_link_list.$list;
    }

    This will create a gallery page with an alphabetical index at the top that links to the Alphabetical anchors with your terms. Also includes a short summary of the term (from excerpt or content) - 25 words max - and adds a '... [more]' to the end of the line if it truncates the definition.... It does ignore the tooltip hover though...

    There are a few more styles used, you can do something like:

    a.glossaryIndexAnchor {color: #111111;}
    a.glossaryIndexAnchor:hover {color: #111111;}
    
    .glossaryIndexAnchor{
    	display: block;
    	width: 100%;
    	border-bottom: 1px #CCC solid;
    	font-size: 2.0em;
    	margin-top: 15px;
    	padding-bottom: 5px;
    }
    .glossaryIndex{
    	margin: 0 auto;
    	font-size: 1.5em;
    	text-align: center;
    }
    
    .glossaryIndexLink{}
    .glossaryTerm{}

    have fun!

  4. janrozehnal
    Member
    Posted 3 years ago #

    Wau, thanx :))

    Cool additions.

    Question - can you fix utf8 support for this plugin? I can't :(

    For exapmle word "Black" is ok but in Czech "Černá" not working.

    Anyway thanx :)

  5. vivahume
    Member
    Posted 3 years ago #

    sorry - i don't have much knowledge of the various encodings..

    I realize I assumed english for the "alphabetical" listing... :o(

  6. Nando
    Member
    Posted 3 years ago #

    nice, really nice but...there's a problem with UTF8 encoding..

  7. Nando
    Member
    Posted 3 years ago #

    ok i changed this from vivahume:

    if (get_option('red_glossaryTooltip') == 1) {
            /* new */
    	if(!empty($glossary_item->post_excerpt)){
    		$tip = $glossary_item->post_excerpt;
    	}elseif(preg_match('/\n+/', $glossary_item->post_content)){
    		$tip = preg_replace('/\n/', '<br/>', $glossary_item->post_content);
    	}else{
    		$tip = $glossary_item->post_content;
    	}
    
    	if (str_word_count($tip) > 50) $tip = implode(' ',array_slice(str_word_count($tip,1),0,50)).'...';
    
    	$link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . addslashes($tip) . '\');" onmouseout="tooltip.hide();">$1</a>';
    	/* end new */

    to this:

    if (get_option('red_glossaryTooltip') == 1) {
                  /* new */
                	if(!empty($glossary_item->post_excerpt)){
                		$tip = $glossary_item->post_excerpt;
                	}else{
                		$tip = $glossary_item->post_content;
                	}
                  if (str_word_count($tip) > 50) $tip = substr($tip,0,strrpos(substr($tip,0,250)," ")).'...';
                	$link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) . '" title="Glosario: '. $glossary_title . '" onmouseover="tooltip.show(\'' . addslashes($tip) . '\');" onmouseout="tooltip.hide();">$1</a>';
                	/* end new */

    this solve the problem with UTF8 encoding...
    but the problems persist with style...there are limits :(

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic