HEX
Server: nginx/1.26.3
System: Linux debian 6.1.0-31-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.128-1 (2025-02-07) x86_64
User: root (0)
PHP: 5.6.40
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/gxdaosen.net/wp-content/themes/simplepark/widget/nav.php
<?php 

class nav extends WP_Widget {

	function nav()
	{
		$widget_ops = array('classname'=>'nav','description' => '自动调用页面和分类目录的树形层级链接,如果没有层级,那么他就不会显示出来[注意,这个模块首页无效]');
		$control_ops = array('width' => 200, 'height' => 300);
		parent::WP_Widget($id_base="nav",$name='自动调用页面和分类树形层级',$widget_ops,$control_ops);  

	}

	function form($instance) { 
		
	?>
	




	<?php
    }
	function update($new_instance, $old_instance) { // 更新保存
		return $new_instance;
	}
	function widget($args, $instance) { // 输出显示在页面上
	extract( $args );
	     $id =$instance['id'];
        $before_content = $instance['before_content'];
        $after_content = $instance['after_content'];
		
     

		
		?>
       
  <?php if(is_category()) {?>
 <?php       
          $cat2 = get_query_var('cat'); 
          $cat = get_category_root_id($cat2);
          $category = get_category($cat);
				  
				   ?>
          <?php if ( get_category_children($cat) != "" ) { ?>      
  <div class="widget  widget_nav_menu">

  <h2>
    <a><?php echo $category->name ; ?></a><b><?php echo $category->slug ; ?></b>
  
  </h2>

    <ul> <?php  if ( get_category_children($cat) != "" ) {wp_list_categories("child_of=".$cat."&depth=0&hide_empty=0&title_li="); }?></ul>
</div>

<?php } }?>


 <?php if(is_single()) {?>
 <?php       
          $cat2 = get_query_var('cat'); 
         $cat = get_category_root_id(the_category_ID(false));
          $category = get_category($cat);
				  
				   ?>
          <?php if ( get_category_children($cat) != "" ) { ?>      
  <div class="widget  widget_nav_menu">


   <h2>
    <a><?php echo $category->name ; ?></a><b><?php echo $category->slug ; ?></b>
  
  </h2>
  
 

    <ul> <?php  if ( get_category_children($cat) != "" ) {wp_list_categories("child_of=".$cat."&depth=0&hide_empty=0&title_li="); }?></ul>
</div>

<?php } }?>
  <?php if(is_page()) {;?>
  
    <?php    global $wpdb;global $post;  
	        $post_data = get_post($post->ID, ARRAY_A);
			$slug = $post_data['post_name'];
			$name = $slug; //page别名
			$parent_id =get_post($post->post_parent, ARRAY_A);
			$parent_slug = $parent_id['post_name'];
			$parent_title = get_the_title($post->post_parent);
			$parent_link =get_page_link($post->post_parent);
        	$childrensd=wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");
        	if($childrensd !="" ||$post->post_parent){
			 ?>
       <div class="widget  widget_nav_menu">


<h2>
    <a><?php if($post->post_parent){ echo $parent_title ;}else{echo  get_the_title();} ; ?></a><b><?php if($post->post_parent){ echo $parent_slug;}else{echo $slug;}  ?></b>
  
  </h2>
   
          <?php if($post->post_parent):  ?>
          <ul>  <?php $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=1"); if ($children){ echo $children; }  ?></ul>
        <?php else: ?>
         <ul> <?php  $children = wp_list_pages("title_li=&child_of=". $post->ID."&echo=0&depth=1");  if ($children){ echo $children; }?></ul>
           <?php endif; ?> 
        
        
</div>
       
        <?php
	}}}
}
register_widget('nav');
?>