[resolved] Upload file (like pdf) and display as a link (5 posts)

  1. aledan
    Posted 6 years ago #

    Hi! I have a problem with file attachment. After I have uploaded a file (pdf) in a post I wanna display it as a link (when you click on it the browser ask for download or open it) in a place I have reserved for pdf attachment in the single.php page. So I don't want use "Inset into post" function.

    Now, I can do this with image thanks to this function.

    How I can do for other file? (like pdf?)

    Thanks and sorry for my little english

  2. MichaelH
    Posted 6 years ago #

    Just put a link that is that file's URL in either the post content, the page content, or even the template.

    I believe most browsers will display the PDF and give you the option to save it.

  3. aledan
    Posted 6 years ago #

    Thanks for the reply, but I need a more autometic way for do it :)

    So, after long reading and surfing, I wrote this function.

    <?php function postfile() {
    	if ( $files = get_children(array(
    		'post_parent' => get_the_ID(),
    		'post_type' => 'attachment',
    		'order' => 'ASC',
    		'orderby' => 'ID',
    		'post_mime_type' => 'application',)))
    		foreach( $files as $file ) {
    			$file_title = $file->post_title;
    			echo '<a href="'.$attachmenturl.'">'.$file_title.'</a>';
    	} else {
    		echo "Nessun allegato disponibile";
  4. cebradesign
    Posted 6 years ago #

    thanks for the function! it's very helpful! ;)

  5. AichandMokie
    Posted 5 years ago #

    I can't seem to understand how to use this.

    What does the function do? As I am also looking for an automatic PDF downloadlink. An easy to use "place PDF, and the it shows as a PDF downloadable link on the post" function.

    I am not familier to the functions php codings in wordpress yet, but I am trying to learn.

    Anyone care to explain this function for me?

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.