Ideas

Internal, wiki-like linking

  1. Covi
    Member

    12345

    Right now, I use this smaller functionality:

    function showPageData($title = '', $format = 'completeLink') {
    	// # Parámetros base:
    	$format 	= !empty($format) ? $format : 'completeLink';
    	$name 		= wp_filter_nohtml_kses($title);
    	$postTitle 	= apply_filters('post_title', $name);
    	if ( isset($postTitle) && !empty($postTitle) ) {
    		// Buscando la página:
    		$pageData 	= get_page_by_title("{$postTitle}");
    		if ( null == $pageData )
    			return 'Página no encontrada';
    
    		// Permalink correcto:
    		$pagePermalink = get_permalink($pageData->ID);
    
    		// Extrayendo un dato:
    		switch ( $format ) {
    			default :	/* completeLink */
    				return "<a href=\"{$pagePermalink}\" title=\"Ir a {$pageData->post_title}\">{$pageData->post_title}</a>";
    				break;
    			case 'permalink' :
    				return $pagePermalink;
    				break;
    			case 'ID' :
    				return $pageData->ID;
    				break;
    			case 'status' :
    				return $pageData->status;
    				break;
    		}
    	} else {
    		return 'Título incorrecto';
    	}
    }
    /* Alias para el shortcode */
    function aliasShowPageData($atts) {
    	// Shortcode:
    	extract(shortcode_atts(array(
    		'title'		=>	$title,
    		'format'	=>	$format
    	), $atts));
    	return showPageData($title, $format);
    }
    // Shortcode:
    add_shortcode('CmsT_pageData', 'aliasShowPageData');
    Sorry by lang spanish in code.
    I hope this is useful ;)

    Posted: 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.

  • Rating

    12345
    80 Votes
  • Status

    This is plugin territory