• Resolved wyndom

    (@wyndom)


    Here’s what I’d like, a post that has an associated media file to receive some sort of CSS styling capabilities. This is needed because the author of this site will not be able to add HTML/CSS tags.
    So, instead of just a text link, I’d like a class or ID that I can add some sort of styling to.

    The post looks like this…
    Post Title = Hey check out our new PDF document
    Post Text = This is a new pdf document, blah blah blah.
    Post Media = the PDF document styled/positioned/etc

    I’m not sure how to achieve this, but keep in mind that the site’s author won’t be able to add HTML.

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi

    (@esmi)

    Create an attachment.php template file in your theme.

    Thread Starter wyndom

    (@wyndom)

    isn’t attachment.php a separate page? I want this to show up on the post’s page and in the loop.

    esmi

    (@esmi)

    If you want to use it in single.php, you’d have to run a secondary Loop to check whether the current post has any attachments with the appropriate mime type.

    Thread Starter wyndom

    (@wyndom)

    Thank you esmi, I was able to achieve what I wanted.
    Here’s the code.
    I’m using a WP_Query to grab all of the posts in a specific category. Then adding a secondary loop (thank you) to that to determine if there is an attachment, and if there is, what type of attachment it is by using get_post_mine_type. From there I’ll use that info to run specific CSS/HTML code to add styles to the resuls

    <?php
        $resources_list = new WP_Query('cat=4');
            while ($resources_list->have_posts()) : $resources_list->the_post(); ?>
                <a>"><?php the_title(); ?></a>
                <?php the_content(); ?>
                <?php
                    $args = array(
                        'post_type'   => 'attachment',
                        'numberposts' => -1,
                        'post_status' => null,
                        'post_parent' => $post->ID
                        );
                    $attachments = get_posts($args);
                        if ($attachments) {
                            foreach ($attachments as $attachment) {
                                if (get_post_mime_type($attachment->ID) == 'application/pdf') {
                                    // do PDF stuff
                                } else if (get_post_mime_type($attachment->ID) == 'application/msword') {
                                    // do WORD stuff
                                } else if (get_post_mime_type($attachment->ID) == 'application/vnd.ms-powerpoint') {
                                    // do PPT stuff
                                }
                            }
                        }
                ?>
    <?php endwhile; ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Style a Post's uploaded media’ is closed to new replies.