styling a list of file attachments
-
I’m sort of a noob at wordpress and I have searched the codex and forums for a solution to this and have only found partial answers thus far. I hope some nice person out there can help me figure out the complete way to implement a custom-styled list of file attachments including custom icons for each file type on my single-post and attachment templates. Here’s the deal…
The site I designed and created a custom theme for is unitedlightgroup.com. It’s main contents are basically a product catalog where each product entry is a post displayed via the Single.php template, like this example: Estrema.
As you can see near the bottom of the page I have used the standard WP gallery shortcode to list additional images. Below that I am listing file attachments—for most products there is at least one pdf, and other files like dwg and ies. I’m currently using a plugin called EG-Attachments to display these files, but I am not happy with the functionality and I have found that what I need to do can be accomplished more smoothly with some well-written php for my template. I have read on some discussions that I could use this code snippet to get the list, and it worked when I tested it but I could not figure out how to style it properly so it would look how I wanted:
<?php $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_mime_type' => 'application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf, application/acad, application/x-acad, application/autocad_dwg, image/x-dwg, application/dwg, application/x-dwg, application/x-autocad, image/vnd.dwg, drawing/dwg, application/octet-stream', 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts($args); if ($attachments) { foreach ( $attachments as $attachment ) { echo the_attachment_link( $attachment->ID , false ); } } ?>
Can someone point out where/how I can insert my css here in order to format the way this list shows up in the template? I have it enclosed in <h3> tags, so the font looks good already. But I have not figured out how to make sure it displays in a horizontal row with 10px of space between each link. Plus, I want a specific icon to show for each mime-type, like the plugin is doing with my current example.
I can’t stick with the plugin because I do not want those labels showing up next to the file names and there is no way to turn that off. Also, when you click on one of the additional images from the gallery, I need to be able to call the parent post in the attachments list so that it will show up there too (I want it to look the same as on the product page with only the image swapped out). The plugin I’m using will not allow me to hack the shortcode in order to reference the parent post and show its attachments, so I think a manual solution involving the above code is my best option.
- The topic ‘styling a list of file attachments’ is closed to new replies.