Created
November 13, 2012 09:37
-
-
Save torounit/4064897 to your computer and use it in GitHub Desktop.
子サイトの一覧を持って来るクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Child_Blog { | |
public $count = 3; | |
public $list_page = 0; | |
public function set_list_page(){ | |
if($this->list_page){ | |
return $this->list_page; | |
} | |
else { | |
global $post; | |
return $post->ID; | |
} | |
return 0; | |
} | |
public function get_blog_ids( $paged = 1 ) { | |
global $wpdb; | |
if($paged < 1) { | |
$paged = 1; | |
} | |
$sql = "SELECT blog_id FROM wp_blogs WHERE public = '1' AND blog_id != '1' ORDER BY last_updated DESC LIMIT ".$this->count*($paged-1).", ".$this->count ; | |
return $wpdb->get_results( $wpdb->prepare( $sql ) ); | |
} | |
function previous_list_link() { | |
$paged = get_query_var('paged'); | |
if($paged < 3){ | |
return get_permalink($this->set_list_page()); | |
} | |
$previouspaged = $paged - 1; | |
return get_permalink($this->set_list_page())."page/".$previouspaged; | |
} | |
function the_previous_link(){ | |
if($this->previous_list_link()){ | |
?> | |
<a href="<?php echo $this->previous_list_link();?>">前のページ</a> | |
<?php | |
} | |
} | |
function next_list_link() { | |
global $wpdb,$post; | |
$paged = get_query_var('paged'); | |
if($paged < 1) { | |
$paged = 1; | |
} | |
$sql = "SELECT blog_id FROM wp_blogs WHERE public = '1' AND blog_id != '1' ORDER BY last_updated DESC LIMIT ".$this->count*($paged).", ".$this->count ; | |
$next = $wpdb->get_results( $wpdb->prepare( $sql ) ); | |
if(empty( $next )) { | |
return false; | |
} else { | |
$nextpaged = $paged + 1; | |
return get_permalink($this->set_list_page())."page/".$nextpaged; | |
} | |
} | |
function the_next_link(){ | |
if($this->next_list_link()){ | |
?> | |
<a href="<?php echo $this->next_list_link();?>">次のページ</a> | |
<?php | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$child_blog = new Child_Blog(); | |
$child_blog->count= 5;//5サイトずつ持って来る。デフォルトは3つ。 | |
$blogs = $child_blog->get_blog_ids(get_query_var('paged')); | |
foreach ($blogs as $key => $blog) { | |
if($blog->blog_id != 1) { | |
switch_to_blog( $blog->blog_id ); | |
//この中でget_posts()するなり、WP_Queryするなり。get_option()するなり。 | |
} | |
} | |
<?php $child_blog->the_previous_link();//前のページへ?> | |
<?php $child_blog->the_next_link();//次のページへ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment