1
votes

I have a custom posttype in Wordpress 3. I would like to every post of this type to have the option to add a link. Basicly this will be a link that refers to another page/post whatever on the site.

There should be only one link for each post of this type. And i would then need to extract this link in my template files. Basicly im creating a post-type "Slideshow" And each slide-item should be connected to one page or post. So when you click a slide you will be taken to the defined page.

i know i can do this by using a custom-field. But then i would need to enter the whole url every time. I would like a feature similar to that of the wordpress WYSIWYG editor link button. So i can add a link to "existing content" easy.

Anyone know of any tutorials or similar on how to do this?

Thanks!

3
Even if are using add a link feature like WYSIWYG editor, you need to add links to each post right.So whats the difference !Gowri
No. Thats the point. Using the add-link feature on the WYSIWYG gives you the option to choose from existing content. And link will be created automaticlyuser829237

3 Answers

1
votes

bit surprised no one has mentioned this plugin "Related Links" Wordpress plugin Related Links

It adds a metabox to your edit forms. You can link to related content or put in external URL.

It allows links to posts, pages, media AND Custom post type - check its type on the Settings page of the plugin after install. It uses a similar search/browse facility to the normal WYSIWYG link insert feature!

What post-types does it apply to? If you are using on a custom post type, then check all the post-types you want to be able to link to - it still shows the box on this post-type itself.

It can accept multiple links, but one will work of course. Then you use the get_related_link() function in your template to output this and format as you like.

0
votes

If you just want to make a link between the two posts, rather than insert it in your post content, I'd recommend the Posts 2 Posts plugin. It'll allow you to create links between posts without having to remember the full URL.

Edit:

I haven't used it, but I suspect the cardinality argument should help you limit the number of links - see the wiki.

And you can certainly access the connections in your templates - I have. Once you've registered your connection type, you can just call get_connected:

    $venue_details = p2p_type( 'exhibition_to_venues' )->get_connected( $post->ID, array(
        'posts_per_page' => -1,
        'connected_orderby' => 'order',
        'connected_order' => 'ASC' )
    );
0
votes

It seems to me that the best method to accomplish this would be to add a custom meta box to all posts and post types (see here:http://themefoundation.com/wordpress-meta-boxes-guide/). Within this meta box, you can simply query all posts that you would like to include in a dropdown. You can then select the post from that dropdown, obtain the ID of the post selected (use as data attribute in the option field), and then return the permalink for that ID. This will then allow you to simply select the post, rather than having to know the actual URL each time.

Another method would be to attach a piece of unique data to x post (most likely utilizing custom fields), and then also attach it to y post. In this way, you could use a function to automatically append the link to the displayed post. You would do this by querying the posts in the database, match the custom data, and if matched, display the link to that post. This would allow the entire thing to be automated, and you wouldn't even have to select anything. In my opinion, the title field should actually be sufficient for this, since both posts are different post types (you should be able to title them the same), and would likely make your query a bit easier/shorter since you would simply need to find the post that matches the title, and then link to the permalink.

I can elaborate on all of the above further, with code samples as well, but in my opinion, the question is slightly too vague to write a custom script example for this scenario.

I would hope the above would be sufficient to get you going.