term_relationships." as rel LEFT JOIN ".$wpdb->term_taxonomy." as tax ON rel.term_taxonomy_id = tax.term_taxonomy_id LEFT JOIN ".$wpdb->links." as lin ON rel.object_id = lin.link_id LEFT JOIN ".$wpdb->terms." as ter ON tax.term_id = ter.term_id WHERE tax.taxonomy = 'link_category' AND lin.link_visible = 'Y' ORDER BY ter.slug ASC, lin.link_name ASC"; $sqlres = $wpdb->get_results($stmt); # Load Template if ($options['thumb_layout']=="left"){ $tpl = file_get_contents(dirname(__FILE__).'/templates/all_links.html'); } else { $tpl = file_get_contents(dirname(__FILE__).'/templates/all_links2.html'); }; # Get Link Part from Template preg_match("/\<\!\-\-category\:start\-\-\>(.*?)\<\!\-\-category\:stop\-\-\>/sim",$tpl,$categoryparts); preg_match("/\<\!\-\-link\:start\-\-\>(.*?)\<\!\-\-link\:stop\-\-\>/sim",$tpl,$tplparts); $last_term = null; # Parse now the results... foreach($sqlres as $link){ # Category? if($link->categoryname != $last_term){ $res .= str_replace('{category}',$link->categoryname,$categoryparts[1]); $last_term = $link->categoryname; } $REPLACE = array( '{image}', '{link_name}', '{link_description}', '{link_url}' ); $REPLACE_WITH = array( ' ', $link->link_name, $link->link_description, $link->link_url ); $res .= str_replace($REPLACE,$REPLACE_WITH,$tplparts[1]); } $tpl = str_replace(array($tplparts[0],$categoryparts[0]),array($res,''),$tpl); return str_replace('[mylinks]',$tpl,$content); } } ############################################################################################################## # Get thumbnails by category ############################################################################################################## add_filter('the_content','getMyLinksByCategory'); function getMyLinksByCategory($content){ return preg_replace_callback('/\[mylinks=(.*?)\]/sim','getMyLinksByCategoryCallback',$content); } function getMyLinksByCategoryCallback($matches){ global $wpdb, $table_prefix; $stmt = " SELECT lin.*, ter.slug, ter.name FROM ".$wpdb->term_relationships." as rel LEFT JOIN ".$wpdb->term_taxonomy." as tax ON rel.term_taxonomy_id = tax.term_taxonomy_id LEFT JOIN ".$wpdb->links." as lin ON rel.object_id = lin.link_id LEFT JOIN ".$wpdb->terms." as ter ON tax.term_id = ter.term_id WHERE tax.taxonomy = 'link_category' AND (ter.slug = '".$matches[1]."' OR ter.name = '".$matches[1]."') AND lin.link_visible = 'Y' ORDER BY lin.link_name ASC"; $sqlres = $wpdb->get_results($stmt); # get mylinks2 options from db $options = get_option('mylinks2_plugin_options'); if(count($sqlres) >= 1){ $res = ''; # Load Template $tpl = file_get_contents(dirname(__FILE__).'/templates/one_category.html'); # Get Link Part from Template preg_match("/\<\!\-\-link\:start\-\-\>(.*?)\<\!\-\-link\:stop\-\-\>/sim",$tpl,$tplparts); # Parse now the results... foreach($sqlres as $link){ $REPLACE = array( '{image}', '{link_name}', '{link_description}', '{link_url}' ); $REPLACE_WITH = array( '', $link->link_name, $link->link_description, $link->link_url ); $res .= str_replace($REPLACE,$REPLACE_WITH,$tplparts[1]); } $tpl = str_replace($tplparts[0],$res,$tpl); return $tpl; }else{ return ''; } } ############################################################################################################## # Add one Thumb to the content ############################################################################################################## add_filter('the_content','getMyLinksThumb'); function getMyLinksThumb($content) { return preg_replace_callback("/\[thumb\](.*?)\[\/thumb\]/sim","getMyLinksThumbCallBack",$content); } function getMyLinksThumbCallBack($content){ # get mylinks2 options from db $options = get_option('mylinks2_plugin_options'); return ''; } ?>