Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think you can just take it from the database. It would look something like this. And take a look at the names used in the table – you can use all of those.

    global $wpdb;
    $attachments = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'posts WHERE post_type="attachment");
    foreach ($attachments as $attachment) {
       echo $attachment->post_title;
       // etc your code goes here (display what you want)
    }

    Hi, I did similar sidebars in my last template, and used something like this in my functions.php:

    if ( function_exists('register_sidebar') ) {
    	$args = array(
    			'post_type'=>'page',
    			'post_parent'=>0,
    			'order'=>'DESC'
    			)
    	$pages = get_posts($args);
    	foreach ($pages as $page) {
    		register_sidebar(array('name'=>$page->post_title,
    	        'before_widget' => '<div id="%1$s" class="widget %2$s">',
    	        'after_widget' => '</div>',
    	        'before_title' => '<h2 class="widgettitle">',
    	        'after_title' => '</h2>',
    		));
    	}
    }
    function find_parent($id) {
    	$this_post = get_post($id);
    	if ( !$parent_id=$this_post->post_parent ) {
    		find_parent($parent_id);
    	} else {
    		return $id;
    	}
    }

    I haven’t checked if it works, but apart from some minor mistakes – it should.

    And then just put this in your sidebar.php and it should remove your manual labour afterwards.

    $parent_id = find_parent($post-ID);
    $parent_page = $get_page($parent_id);
    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar( $parent_page->post_title ) ) echo "";

    Just a note though – if your client deletes / changes the order of top-level pages, the sidebars might jump from one page to another. Adding new pages without deleting the previous should work fine.

    mkalis

    (@mkalis)

    I tried a bit safer thing – I changed the permissions for wp-content to 777 (with no recursion), and the automatic update created a subdirectory ‘upgrade’ with permissions 775 – so my guess is if you just create the subdirectory ‘upgrade’ with permissions 775 it should work (I’ll test it when I need a new upgrade).

Viewing 3 replies - 1 through 3 (of 3 total)