Forums

[resolved] Styling a page of attachments (3 posts)

  1. taiga
    Member
    Posted 2 years ago #

    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.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    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.

  3. taiga
    Member
    Posted 2 years ago #

    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>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.