- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I am using a simple function to pull all PDF and MSWord documents attached to a post (a custom post-type) and return them in an unordered list for download, like so:
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'application/pdf,application/msword',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'orderby' => 'menu_order',
'order' => 'desc'
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
echo '- ID).'" target="_blank">Download ';
';
echo $attachment->post_title;
echo ' - (';
echo $attachment->post_mime_type;
echo ')
}
}
?>
Simple enough. But the outputted HTML return “Download XYZ Document Title (application/pdf)”.
I want it to return a ‘friendlier’ name for the file type, like so, “Download XYZ Document Title (PDF)”
Is there any way to achieve this?
Thanks in advance for any help.
Hey Traq. Thanks for the reply.
I’ve only ever used a translate function to change “Posts” to say “Articles”… But even that was from a tutorial.
Any hints / snippets?
Hi Traq
My code above resides in archive-downloads.php
I am echo-ing the resulting text, not printing.
Feel a bit stupid right now… Where are you suggesting your snippet should go – functions.php? Also, how does the “print friendly_mime” but fit in..?
Aaaah…
Thanks Traq and Schmotty – worked like a charm and I’ve learnt something new.
Cheers