Advanced Custom Bookmark Query
-
Hey all,
I’ve been looking around here for a couple of days now. I know the codex wp_list_bookmarks, and I found Otto’s query below:<?php $taxonomy = 'link_category'; $title = 'Link Category: '; $args =''; $terms = get_terms( $taxonomy, $args ); if ($terms) { foreach($terms as $term) { if ($term->count > 0) { echo '<p>' . $title .' ID = '. $term->term_id . ' ' . $term->name . ' contains ' . $term->count . ' link(s). </p> '; } } } ?>
(which i thought was pretty cool)
If someone has a way to accomplish the following, it’d really help me out:
I have a set of pages set up to use the same template (issues.php) Now, i have it all dynamically set up so that the template knows which page it is and it calls in posts related to that page (by a custom field selection) using a custom query. My hope was to have a section of related “outgoing links” on the pages as well…So I need a way to query the database, check to see if there are links in the necessary category. If there are, create a wrapper div that will hold the list of links.
I hope that makes sense, Here is an example of the code i’m using to pull in related posts, I guess I need something like this, but querying the links instead?
<?php /* QUERY FOR RELATED BLOG POSTS */ $querystr = " SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id) LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE $wpdb->term_taxonomy.term_id = 15 AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->posts.post_status = 'publish' AND $wpdb->postmeta.meta_key = '$issueCategory' AND $wpdb->postmeta.meta_value = 'on' ORDER BY $wpdb->postmeta.meta_value ASC LIMIT 4 "; ?> <?php /* RELATED BLOG POSTS DISPLAY */ ?> <?php $pageposts = $wpdb->get_results($querystr, OBJECT); if ($pageposts): ?> <div id="recentPosts" class="module"> <div class="title">Related Posts</div> <?php foreach ($pageposts as $post): ... so on and so forth
Thanks in advance to anyone who can point me in the right direction
- The topic ‘Advanced Custom Bookmark Query’ is closed to new replies.