WordPress.org

Forums

[Plugin: Flexi Pages Widget] link target compatibility with Page Links To (1 post)

  1. Darrell Schauss
    Member
    Posted 4 years ago #

    I have added a few lines to Flexi Pages Widget 1.6.3 in order to get the link target defined in Page Links To 2.3 plugin.

    It runs a db query for every link but there is probably a better way to get the link target ahead of time into the $page_array.

    In flexi-pages-widget.php
    Old:

    function flexipages_list($page_array, $level = 0)
    	{
    		if(!$page_array)
    			return;
    
    		foreach($page_array as $page) {
    
    			if($page['date']) $date = " ".$page['date'];			
    
    			$pagelist .= str_repeat("\t", $level+1).'<li class="'.$page['class'].'"><a href="'.$page['link'].'" title="'.$page['title'].'">'.$page['title'].'</a>'.$date;
    			if($page['children'])
    				$pagelist .= flexipages_list($page['children'], $level+1);
    			$pagelist.= "</li>\n";
    		}
    		if($pagelist)
    			$pagelist = str_repeat("\t", $level)."<ul>\n{$pagelist}".str_repeat("\t", $level)."</ul>";
    		return $pagelist;
    	}

    New:

    function flexipages_list($page_array, $level = 0)
    	{
    		if(!$page_array)
    			return;
    
    		foreach($page_array as $page) {
    
    			if($page['date']){ $date = " ".$page['date'];}
    
    			//added for compatibility with Page Links To
    			global $wpdb;
    			$page_target = $wpdb->get_var($wpdb->prepare("SELECT <code>meta_value</code> FROM wp_postmeta WHERE <code>post_id</code>='%s' AND <code>meta_key</code>='_links_to_target'",$page['ID']));
    			$page_target = trim(strip_tags($page_target));
    			$page_target = ($page_target == "")?"":'target="'.$page_target.'"';
    
    			$pagelist .= str_repeat("\t", $level+1).'<li class="'.$page['class'].'"><a href="'.$page['link'].'" title="'.$page['title'].'" '.$page_target.'>'.$page['title'].'</a>'.$date;
    			if($page['children'])
    				$pagelist .= flexipages_list($page['children'], $level+1);
    			$pagelist.= "</li>\n";
    		}
    		if($pagelist)
    			$pagelist = str_repeat("\t", $level)."<ul>\n{$pagelist}".str_repeat("\t", $level)."</ul>";
    		return $pagelist;
    	}

    http://wordpress.org/extend/plugins/page-links-to/
    http://wordpress.org/extend/plugins/flexi-pages-widget/

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 4 years ago by Darrell Schauss
  • This topic is not a support question
  • WordPress version: 3.0.1