Link title to PDF or external URL
-
I want to add some content without real content but instead just have a direct link to a sister site or a direct downloads of a PDF. Is there a way to do this so I can skip the extra step of “click here to view” in my post?
-
Do you mean that you want to add a post, and when that post is clicked on you want it to download a PDF rather than actually linking to the post?
Yes, that is what I am hoping to do. Any ideas?
Put this in a page:
<embed src="https://www.mysite.nl/wordpress/wp-content/uploads/2009eindstand.pdf" width='770' height='490'</embed>
after uploading the wanted file through media upload.
but do not go to WYSIWYG because that will kill the code.
Got this today from another topic and the idea was from Samboll (I believe, can’t find it back now)
Not a bad idea. But there are a few drawbacks that make it not work for me.
1. When you click on the post it still links to the post instead of leaving you on the page.
2. In FF the default seems to be to load it outside the window in Adobe Reader so if you load a page that has this post it automatically loads that PDF by default.
3. It doesn’t work for me in IE8. That may just be me though. I changed it to iframe and it works like FF above but gives me a download file warning.
Ultimately I’m also looking for a solution that allows you to use an external URL. I could use iframes for that but would prefer a direct link in some cases.
Well, I believe after looking at Custom Fields that this is the way to go. I found that using custom fields called “link” and “target” will work to post a link to any file or website with any target (or this code defaults to _blank). Here is how I modified index.php in the default theme. I need to modify the category and archive pages as well but this is the general idea on the blog homepage:
<div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <?php $post_id = get_the_ID(); $linkVal = get_post_meta($post_id, 'link', false); $linkVal = $linkVal[0]; if ($linkVal) { $targetVal = get_post_meta($post_id, 'target', false); $targetVal = (!is_array($targetVal)) ? '_blank' : $targetVal[0]; ?><h2><a href="<?php echo $linkVal; ?>" target="<?php echo $targetVal; ?>" rel="bookmark" title="Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2><?php } else { ?> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> <div class="entry"> <?php the_content('Read the rest of this entry »'); ?> </div> <p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p> <?php } ?> </div>
Hi Andrew, I am afraid that coding is a bit over my head.
It does work for me in FF. Check this link out:
https://www.enduro.nl/eindstanden-enduro-nl/2009-enduro-nl-eindstanden/This is one of 14 child-pages from here:
https://www.enduro.nl/eindstanden-enduro-nl/I don’t know about IE8 (will test later) Browsershots is too busy now.
I needed my trick because the newest year list (2009) was only supplied in Acrobat and converting it to my old format is too much pain. Besides, with the old pre formatting I hit a character limit and had to put a workaround in my config file (but that’s another story).
By the way, I was out for a long day and we are in different timezones, hence the delayed response.
It looks like your solution works well in FF and IE for me. I was trying to get it to download the PDF rather than embed it like you have done so I will have to see if this will work just as well, as I think it looks rather nice how you have done it!
Can I ask if your page at https://www.enduro.nl/eindstanden-enduro-nl/ is automatically updated when you add a sub page like https://www.enduro.nl/eindstanden-enduro-nl/2009-enduro-nl-eindstanden/ ?
If so, may I ask how you went about that? My ultimate goal for this project is to make a quick news list out of a category that is automatically updated when you add an item to that category. I think it will look a lot like https://www.enduro.nl/eindstanden-enduro-nl/ but I am hoping to have posts automatically added to the list as the users all add things.
Thanks!
AndrewYes Andrew, it does it automatically. I choosed this because I saw no method to do it in a menu (there are 15 children now and it will grow for a long time with one per year).
The trick is sort of described here:
https://codex.www.ads-software.com/Pages#Page_Templates and here
https://codex.www.ads-software.com/Creating_an_Archive_IndexIn short:
create an empty (mother) page.
create a specific page-template for that empty mother page<?php /** * @package WordPress * @subpackage Default_Theme */ /* Template Name: eindstandenarchief */ ?> <?php get_header(); ?> <?php include('left_sidebar.php'); ?> <div id="container"> <div class="entry"> <h2>Hier vindt u de eindstanden van het ONK Enduro vanaf 1995:</h2> <ul> <?php wp_list_pages('sort_column=menu_order&child_of=698&title_li='); ?> </ul> <h4>In het <a target=_"blank" href="https://www.knmv.nl/archive.asp">KNMV archief</a> vindt u de complete uitslagenlijsten vanaf 2003</h4> </div> </div> <?php include('right_column.php') ;?> <?php include('right_sidebar.php') ;?> <?php get_footer(); ?>
then you are set to go and create child-pages and the links will appear in the mother page. (My child-pages also use a specific wide template but that is not relevant).
In the template copy exactly line 6,7 and 8 with the slashes and the (your own) template name (that is a sensitive set of lines with the proper spaces etc).Greetz
- The topic ‘Link title to PDF or external URL’ is closed to new replies.