Forums

make an option page in admin with categories as submenus (1 post)

  1. kim crimson
    Member
    Posted 2 years ago #

    Hi there,

    I'm trying to make a few option pages in admin where each submenu item in the options menu is a category. In each of these category subpages I want a list of all the posts in the category and display some short info based on meta values in a table. Here's what i have so far; I have populated the submenus with the categories, but I'm stuck trying to pull the posts from the category when opening the page.

    <?php
    function admin_styles() {
    	wp_enqueue_style('admin_styles', get_bloginfo('template_url').'/lib/styles/custom-admin.css', false, '1.0', false);
    }	
    
    // Adding the menu pages
    add_action('admin_menu', 'add_submenus');
    add_action('admin_print_styles', 'admin_styles');
    
    function add_submenus() {
    
        // add top level menu:
        add_menu_page('Oversigt', 'Oversigt', 'administrator', 'oversigt', 'create_main_menu');
    
    	// get categories and make submenus
      	$categories = get_categories();
      	foreach ($categories as $category) {
    	    add_submenu_page('oversigt', 'sub menu' , $category->cat_name , 'administrator', $category->category_nicename , 'add_sub_menu_content' );
      	}
    }
    
    function create_main_menu() {
    	echo "<div class='wrap'><h2>Oversigt</h2></div>";
    }
    
    // Creating content for the submenu pages
    function add_sub_menu_content() {
    	global $post;
    
     	// get all rooms in current category
     	$rooms = get_posts('category=1&numberposts=150');
     	sort($rooms);
    ?>	
    
    	<div class="wrap">
    		<!-- Doing too much stuff with the posts to display here -->
    	</div>	
    
    <?php } ?>

    I need to make this line get the current category you are in:

    $rooms = get_posts('category=1&numberposts=150');

    Hoping someone can help me with this! If it's possible at all..

    many thanks!!!

Topic Closed

This topic has been closed to new replies.

About this Topic