PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Help with post forms

  1. Chef2
    Member

    Hello, is it possible to have the 'title' of a post form to recover the 'URL' from a custom URL field and have the post name link to the actual URL ?

    Example: Use the title field as the post title, but in the same time recover the URL field as the final destination for the link created, this would of course create a post and be listed on the WP site but once people click on the final URL it would point to the external URL.

    Blogger has this feature, it lest you link to an external site right from the start of the post.

    Cheers.

    Posted 12 years ago on Wednesday September 14, 2011 | Permalink
  2. Yes this is possible, but it would be done in your template, not in your form. Your form can capture the data, including the custom URL, but then you need to link the post title to the external URL on the single post page.

    Your post template might look like these in single.php where it shows the post title:

    [php]
    <h1 class="entry-title"><?php the_title(); ?></h1>

    You would change it to something like this:

    [php]
    <h1 class="entry-title"><a href="<?php echo get_post_meta($post->ID, 'name_of_custom_field_with_url', true); ?>"><?php the_title(); ?></a></h1>

    That assumes that there is one custom field with a key of "name_of_custom_field_with_url" (which I am certain is incorrect for you and will need to be changed) and it holds the url to the external site. This will link the post title to your external URL.

    Posted 12 years ago on Wednesday September 14, 2011 | Permalink
  3. Chef2
    Member

    Thank you Chris, would this affect the creation of posts in the following event?:

    Poster does not include a URL, he or she actually fills the form thus creating an actual content-based post.

    Thank you.

    Posted 12 years ago on Thursday September 15, 2011 | Permalink
  4. You would have to handle that with conditional logic somehow. Maybe change the post template when the title should be a linked URL. Otherwise, use the regular single.php template.

    The change I mentioned would apply to all single posts. If your requirements are more complex than that, you will need to do additional work to handle all your different use cases.

    Posted 12 years ago on Thursday September 15, 2011 | Permalink