<?php
class THEGLOBALthumbnailspowenkoTutorials extends WP_Widget {
function THEGLOBALthumbnailspowenkoTutorials() {
$widget_ops = array('classname' => 'widget_THEGLOBALthumbnailspowenkoTutorials', 'description' => __('(Sidebar Only) - powenko List Category Tutorials'));
$this->WP_Widget('THEGLOBALthumbnailspowenkoTutorials', __('The Global: List Category Tutorials'), $widget_ops, $control_ops);
}
function fun_get_tutorial_id($name,$category){
// $category = get_the_category();
$catParID = $category->category_parent;
$catParent = get_cat_name ($catParID);
$category2 = get_category( $catParID,false);
// echo $category->name;
// echo $name;
// echo $category2->cat_ID;
// echo ",";
if($category2->cat_ID>0){
if($name!=$category2->name){
return $this->fun_get_tutorial_id($name,$category2);
}else{
return $category;
}
}else{
return NULL;
}
return $category;
}
function FunListAll($cat_id,$iName,$i){
// $cat_id= $Pid->cat_ID;
echo "<h1 class='widget'>";
for($j=0;$j<$i;$j++){
echo ".";
}
echo $iName ."</h1>";
query_posts("cat=".$cat_id."&posts_per_page=100");
if (have_posts()) {
while (have_posts()) {
the_post();
echo '<a href="'.get_permalink().'"> '.get_the_title().'</a><br>';
}
}
}
function widget($args, $instance) {
global $post;
// echo $instance["cat"];
// echo "....";
$TheCategories = $category = get_the_category();
//echo $keyword= $instance["title"];
echo $keyword=get_cat_name( $instance["cat"] );
if( $keyword==""){
$keyword="技術文章"; //"教學文章"; // Tutorials
}
$Pid=$this->fun_get_tutorial_id($keyword,$category[0]);
$this->widget_kernal($Pid->cat_ID,$Pid->name,0);
}
function widget_kernal($id,$name,$i) {
global $post;
$this->FunListAll($id,$name,$i);
$cat_id =$id; // $category[0]->cat_ID;
$childCats = get_categories('child_of='.$cat_id.'&hierarchical=0&parent='.$cat_id);
if(is_array($childCats)):
foreach($childCats as $child){
// echo $child->name;
// echo $child->hierarchical;
// echo "<br>";
$this->widget_kernal($child->cat_ID,$child->name,$i+1);
wp_reset_query();
}
endif;
}
function widget_old($args, $instance) {
global $post;
$TheCategories = $category = get_the_category();
$keyword="技術文章"; //"教學文章"; // Tutorials
$Pid=$this->fun_get_tutorial_id($keyword,$category[0]);
/////// 列出下面的文章
$this->FunListAll($Pid->cat_ID,$Pid->name);
echo $cat_id = $category[0]->cat_ID;
$childCats = get_categories('child_of='.$cat_id.'&hierarchical=0&parent='.$cat_id); //(" 'child_of' => $cat_id ");
//child_of=5&hierarchical=0&parent=5
if(is_array($childCats)):
foreach($childCats as $child){
echo $child->name;
echo $child->hierarchical;
echo "<br>";
wp_reset_query();
}
endif;
?>
<?php
echo $after_widget;
$post = $post_old;
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($instance) {
?>
<p><b>Useage:</b></p>
<p>This widget is only suitable for use within any of the <b>Sidebar</b> widgetised areas.</p>
<p><div style="clear: both; padding-bottom: 5px; margin-bottom: 15px; border-bottom: 1px solid #efefef;"></div></p>
<p><b>Title:</b></p>
<p>
<label for="<?php echo $this->get_field_id("title"); ?>">
<?php _e( 'Widget title:' ); ?>
<input class="widefat" id="<?php echo $this->get_field_id("title"); ?>" name="<?php echo $this->get_field_name("title"); ?>" type="text" value="<?php echo esc_attr($instance["title"]); ?>" />
</label>
</p>
<label for="<?php echo $this->get_field_id("cat"); ?>">
<?php _e( 'Category:' ); ?>
<?php wp_dropdown_categories( array( 'name' => $this->get_field_name("cat"), 'selected' => $instance["cat"] ) ); ?>
</label>
</p>
<p><div style="clear: both; padding-bottom: 5px; margin-bottom: 15px; border-bottom: 1px solid #efefef;"></div></p>
<p><b>Options:</b></p>
<p><div style="clear: both; padding-bottom: 5px; margin-bottom: 15px; border-bottom: 1px solid #efefef;"></div></p>
<?php
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("THEGLOBALthumbnailspowenkoTutorials");') );
?>
Post navigation