Linking to each blog on my multisite install
-
Hi there!
I’m running a multisite install for a political party, with subdirectories for each member of the party.
We have a custom plugin where the admin of each blog can tick a checkbox for “Senator” or “Representative”. This plugin also includes these functions.
function getBlogInfo($key){ global $wpdb, $post, $table_prefix, $blog_id; $q = "SELECT <code>value</code> FROM info_extra WHERE idBlog = '{$blog_id}' AND <code>key</code>='{$key}' "; return $wpdb->get_var($q); } function getBlogInfoByBlogId($key, $blogid){ global $wpdb, $post, $table_prefix; $q = "SELECT <code>value</code> FROM info_extra WHERE idBlog = '{$blogid}' AND <code>key</code>='{$key}' "; return $wpdb->get_var($q); }
And this is the function that saves the data (Senator/Representative) from the backend, to a table in the database called info_extra:
function saveData($key, $value){ global $wpdb, $post, $table_prefix, $blog_id; $q = "SELECT <code>key</code> FROM info_extra WHERE idBlog = '{$blog_id}' AND <code>key</code>='{$key}' "; $exists=$wpdb->get_var($q); if($exists): $q = "UPDATE info_extra SET <code>value</code>='{$value}' WHERE <code>key</code>='{$key}' AND idBlog = '{$blog_id}'"; else: $q = "INSERT INTO info_extra SET <code>idBlog</code>='{$blog_id}', <code>key</code>='{$key}', <code>value</code>='{$value}'"; endif; $post=$wpdb->query($wpdb->prepare($q));
So, on to the problem: I was asked to add two links to our homepage: one reading ‘Senators’ and one reading ‘Representatives’. When someone clicks on, for instance, Senators, they should be taken to a page (www.example.com/senators) that lists the name of each blog that has ticked the Senator checkbox, along with a link to that blog.
So far I’ve got this.
<?php $bloglist = wp_get_sites(); foreach ($bloglist as $blog) { $blogid = $blog[blog_id]; getBlogInfoByBlogId('iSenator', $blogid); } ?>
But I’m not very good at PHP so I’m stumped. I understand my code should return the id of each blog that has has isSenator=1, but I don’t know how to turn that into a human-readable list of blogs with their links.
Care to shed some light on this?
- The topic ‘Linking to each blog on my multisite install’ is closed to new replies.