Are you looking for a way to specify a category using a custom field thecat
to display a listing of links / bookmarks? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display links with description in WordPress.
Instructions:
All you have to do is add this code to your theme’s single.php file:
<?php $theCat = get_post_meta($post->ID, 'thecat', true); ?> <table> <thead> <tr> <th>Bookmark</th> <th>Description</th> </tr> </thead> <?php $bookmarks = array(); $bookmarks = get_bookmarks("category=$theCat"); if ($bookmarks[0] != '') { ?> <?php foreach ( $bookmarks as $bookmark ) {?> <tr <?php if($i%2 == 0){ ?> class="odd"<?php $i++; }else{ $i++; } ?>> <td><a title="<?php echo $bookmark->link_description; ?>" href="<?php echo clean_url($bookmark->link_url); ?>"><?php echo $bookmark->link_name; echo $bookmarks->term_id; ?></a></td> <td><?php echo $bookmark->link_description; ?></td> </tr> <?php }} ?> </table>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 23 best WordPress themes for non-profits and how to track affiliate links in Google Analytics.
Comments Leave a Reply