Aller au contenu
FR

Display WordPress’ Default Link List

Version audio de cet article

Here’s a quick tutorial that will allow you to display your WordPress links (from the Links tag) sorted by category. While this tab is technically a thing of the past, it can be useful to have due to interesting backlinks.

Simply add this code where ever you want.

<?php 
// récuperer la taxonomy des catégories
$taxonomy = 'link_category';
$tax_terms = get_terms($taxonomy);
 
        // si les catégories existent on boucle
	if ($tax_terms) {
	foreach ($tax_terms  as $tax_term) {
	echo '<h2>'. $tax_term->name .'</h2>';
	// on donne les arguments
        $args = array(
	'category' => $tax_term->term_id,
	'orderby' => 'name',
	'order' => 'ASC',
	);
	// On recupere les liens attribués et on boucle
        $bookmarks = get_bookmarks($args);
	foreach ( $bookmarks as $bookmark ) {
	// On affiche les liens correspondants
        printf( '<span class="links">+ <a href="%s">%s</a>',$bookmark->link_url, $bookmark->link_name );
 
	printf( '</span>' );
	}
	}
}
?>

Links are now dynamic and we can n ow create new categories and add custom category links.

If your current configuration of WordPress does not have the Link tab, add the following filter in your functions.php file:

add_filter( 'pre_option_link_manager_enabled', '__return_true' );