Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm not a web developer so I don't know how to create an sql query to display information from my database.

Here's what I wanted to do, I want to have a page that will display blog categories. When a visitor clicked a category, a list of blogs will be displayed under that category.

I already have a table and information stored on my database however, i don't know how to display it on the frontend.

    CREATE TABLE `wp_blog_types` (
  `blog_types_ID` bigint(20) unsigned NOT NULL auto_increment,
  `blog_ID` bigint(20) NOT NULL,
  `blog_types` TEXT NULL,
  `blog_subtypes` TEXT NULL,
  PRIMARY KEY  (`blog_types_ID`)
) ENGINE=MyISAM;

CREATE TABLE `wp_signup_blog_types` (
  `blog_types_ID` bigint(20) unsigned NOT NULL auto_increment,
  `blog_types_domain` varchar(255) NOT NULL,
  `blog_types_path` varchar(255) NOT NULL,
  `blog_types` TEXT NULL,
  `blog_subtypes` TEXT NULL,
  PRIMARY KEY  (`blog_types_ID`)
) ENGINE=MyISAM;

I wanted to display the information based on that sql code by using a shortcode.

share|improve this question

1 Answer 1

It looks like the original poster has not been around for awhile, but I am working on this same plugin trying to figure out a way to make it usable. The developers have been saying for over a year that they are going to get around to up-dating this plugin, but for now you have to invent your own way to use it. In my searches A LOT of people have been asking how to do this: So, here is what I have come up with so far. My PHP skills are minimal, so be short with your mockery and any feedback is very appreciated on how to make this more concise:

I wrote a function that can be placed in the functions.php file, and then you can use the function on any page template like so (just an example):

<h3 class="pagetitle">A List of Categories and Sites</h3>
<?php get_blog_types(); ?> 

and here is the function:

<?php 
 function get_blog_types() {

  global $wpdb , $blog_types , $blog_subtypes;

  //first I get all of the blog_type names
    foreach($blog_types as $blog_type){
       $blog_type_name = $blog_type['nicename'];
        $blogtypenames = $wpdb->get_results("SELECT blog_ID, blog_types FROM wp_blog_types where blog_types = '|$blog_type_name|' ");      //echo the blog-type
            echo '<h3>';
            echo  $blog_type['name'];
            echo '</h3>';


            //Second I get the sites in each blog-type
            foreach( $blogtypenames as $blogtypename ) {

             //Third I get he names of those sites
           $sitename = $wpdb->get_results("SELECT option_value, blog_id FROM wp_".$blogtypename->blog_ID ."_options WHERE       option_name='blogname' ");

           foreach( $sitename as $name ) { 

           $blogs = $wpdb->get_results("SELECT domain,path FROM wp_blogs where blog_id = ". $blogtypename->blog_ID.""); 
        foreach( $blogs as $blog ) {        
            // Create bullet
            echo '<li>';
            echo '<a href="http://';
            echo $blog->domain;
            echo $blog -> path;
            echo '">';
            echo $blogtypename->blog_ID;
            echo $name->option_value;
            echo '</a></li>';
             }; //end fifth
            }; //end fourth
        }; //end third
     }; //end second

    } //end first
?>

I am going to work on it some more to include sub-types and probably just turn it into a plugin once I have it ironed out more, but I thought it would be helpful to get it out for anyone else messing with this.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.