• Resolved taiga

    (@taiga)


    I’ve succesfully been able to create a Gallery page that displays all of the image attachments which have been uploaded. The page is supposed to be a central gallery of all of the images. This has been achieved by using the example code of get_posts from the Codex.

    The problem is that how would you style the output in a neat table? Is there a way to implement gallery shortcode into the get_posts routine?

    To which place should I inject styling tags, if I need to?

    Here is the code:

    <?php
    
    $args = array(
    	'post_type' => 'attachment',
    	'numberposts' => -1,
    	'post_status' => null,
    	'post_parent' => null, // any parent
    	);
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $post) {
    		setup_postdata($post);
    
    		the_attachment_link($post->ID, false);
    		the_excerpt();
    	}
    }
    ?>

    That code is a part of the template of the Gallery page. Without any styling the images are displayed below each other.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Look at the gallery shortcode function in media php. If you copy the markup used in that function when outputting your images, you should also be able to hook into the gallery CSS.

    Thread Starter taiga

    (@taiga)

    I found the solution from elsewhere on the Forums. I’ll probably look into the Gallery short code later. Here’s the solution – with simple html markup added (list for an example):

    <ul>
    <?php
    
    $args = array(
    	'post_type' => 'attachment',
    	'numberposts' => -1,
    	'post_status' => null,
    	'post_parent' => null, // any parent
    	);
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $post) {
                    echo '<li>';
    		setup_postdata($post);
    		the_attachment_link($post->ID, false);
    		the_excerpt();
                    echo '</li>';
    	}
    }
    
    ?>
    </ul>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Styling a page of attachments’ is closed to new replies.