Thursday, January 12th, 2012 | Code, Web Dev, WordPress

{0}

Shortcode to show all files attached to post as list [showfiles]

Here’s the code:

// [showfiles]
function dump_files($atts) {
        extract(shortcode_atts(array(), $atts));
        global $post;
        $return = '';
        $children = get_children( 'numberposts=-1&orderby=menu_order&order=ASC&post_type=attachment&post_parent='.$post->ID );
        if ($children) :
        $return .= '<ul>';
        foreach ($children as $child) {
        $return .= '<li>
            <a href="'.$child->guid.'">'.$child->post_title.'</a>';
            if ($child->post_content):
                $return .='<br>'.$child->post_content;
            endif;
            $return .='</li>';
            } // endfor
        $return .='</ul>';
        endif;
        return $return;
}
add_shortcode("showfiles", "dump_files");
// end shortcode

More later…stay tuned.

Leave a Comment

Recent Posts

WordPress Function to change Background to Featured Image

I needed this functionality, and decided to create a function. Since it was so easily digestable, I figured I’d just post it here. Here’s the function function set_post_background() { global $post; $bgimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID…

Read the Full Article

Customize Password Protected Text Using Custom Fields [WordPress]

I haven’t posted in a very long time, but as soon as I stumbled on this functionality I had to share it immediately, so here it is: It is possible to add a filter function to add new text to the password protected page. The code to add to your functions.php files is as follows: <?php add_filter( '…

Read the Full Article

jQuery Resizer! – resize objects that are greater than a specified width

Today I launched the new design of Escape From Cubicle Nation, which I’m very proud to have worked on. Props to Brian Morykon for the design, Joseph Hinson for the code. My last order of business in coding the site was that some of the Youtube videos and embeds had been inserted at a width of 640 pix…

Read the Full Article

A Bunch of New [old] Posts

Tim wrote a series when I first started called “The 21 Days of WordPress Tips”, which I think there were something like 18 of…but I digress. We’ve been getting traffic on those posts for awhile, and he knew I was geeking out over here, so he told me to export them to this blog an…

Read the Full Article

What to do if a WordPress automatic upgrade fails

If you’ve ever been upgrading a WordPress installation and had it fail, leaving you in the dark depths of maintenance mode, you’ll agree with me that it can be quite a headache. Much like a site launch or a database move, it can take either 5 minutes, or 5 hours, but it never seems to fall in b…

Read the Full Article

Easy way to check for child pages (children) in WordPress

I was trying to create a sub-navigation menu that would only show if there were child pages in WordPress the other day, but to my knowledge, there is no has_children() or has_child() type of conditional available. I’m sure it’s because there are so many other ways to check for children.…

Read the Full Article

Make iframes load after page content (with jQuery)

In my work I create a lot of WordPress sites for my clients, and often times we’ll put the share links and social proof in the footer of each post. Some time ago, facebook introduced the like button for public use with iframes, which makes it very easy to incorporate just about anywhere, the only p…

Read the Full Article

WP-Snippets.com – Great Resource

I write a lot of code snippets on this site, some stuff is found by searching for the solution to a specific problem, others are found by trying to do new things with WordPress. I was thinking of creating a site with code Snippets that could be downloaded by anyone who stumbled on the site, and submitted b…

Read the Full Article