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.

Add links (hyperlinks) by visitors in existing posts?

  1. Chris
    Member

    Hi guys,

    First of all congratulations for all your hard work on this plugin, it looks great at a first glance and since everybody's saying only good things about it, I'm inclined to join the community of the people who bought it.

    But before doing so, I would like you to help me with some details about something I would like to achieve using GF.
    I have a site where I write posts which have in the body links to other sites; basically it's something like this:

    Post title

    [ Some text in the post written by admin ]

    [ Link no. 1 to other site ]
    [ Link no. 2 to other site ]
    [ Link no. 3 to other site ]
    [ Link no. 4 to other site ]

    [ End of the post]

    At this moment the links are added by the admin, but I would like visitors to do this from now on. Is this achievable using Gravity Forms? I would also like to set a specific number of links that can be added (a maximum number of links).
    Another important thing... I want the links to be on this form (hyperlinked):

    <a href="http://thesitesno1address.com" rel="nofollow">Part of the post title</a>

    <a href="http://thesitesno2address.com" rel="nofollow">Part of the post title</a>

    <a href="http://thesitesno3address.com" rel="nofollow">Part of the post title</a>

    Is this doable? I didn't figure it out using only the demo version so I hope you can help with this.
    The purpose behind this functionality is that I want my site to almost sustain itself with the help of it's visitors that will hopefully add those links.

    Thank you in advance for your help,
    Chris

    Posted 14 years ago on Tuesday October 12, 2010 | Permalink
  2. Gravity Forms cannot be used to edit posts.

    You could implement something like this using Gravity Forms but it isn't something it does out of the box and is a more advanced implementation. But it is doable. The links wouldn't be added to the post, they would each be new posts that would be tied to the post using a custom field.

    Here is what you would have to do...

    - Create your original post that contains the content just like you normally would.

    - Create a Gravity Form that creates a new post, assign it to a category where you want to store the user submitted links... create a new one like "Links" and then you will have to hide this category on the front end.

    - Add a Post Custom Field to this form and give it a custom field name of "parentId" default the value to the embed post ID so it stores the value of the post the user is on when they filled out the form in this custom field.

    - Edit your theme template file for the post template the post uses and create a new WordPress loop that displays all posts from the "Links" category that have the custom field key "parentId" that equals the current post id.

    So basically you are going to store the user submitted posts as individual posts, they would have a custom field that contains the main posts id so you can use code to pull just those posts in.

    Like I said, it is completely doable but it isn't something Gravity Forms just does out of the box. It takes setup and creative use of the available tools. Gravity Forms very powerful, and even more so when you take advantage of the available hooks and think outside the box.

    Posted 14 years ago on Tuesday October 12, 2010 | Permalink
  3. Chris
    Member

    Thanks for your reply Carl. I bought today the single license and now I am trying to implement what you said.

    But I'm afraid I'm not very good at coding and I would need your help to get this done. Hope you find a little time for this.

    - First of all, you said I should create a gravity form that creates a new post. Does this mean I have to use a post title field and a post body field together or just a post body field?

    - After creating a post custom field like you said, it remains just to edit the theme template. This means I have to edit the post.php file, I guess, because that's were the posts created with GF are called, right? Can you help with this code, how would it look like?

    To give you an extra info of what I need implemented: I have a site with tv shows; for every episode I want visitors to submit links to it (the anchor being the episode's name); so I want in the form a field where visitors put the name of the episode, then another field where they put a link to a site where the episode is hosted; the links should be in an ordered list.

    Could you help me achieve that, please? Thank you,

    Chris

    Posted 14 years ago on Saturday October 16, 2010 | Permalink
  4. Chris
    Member

    Hi everyone,

    I managed to do what Carl suggested and for the code in the single.php I added this:

    <?php
    $cat_id = get_cat_ID('Links'); //<--your category here
    $args=array(
      'cat' => $cat_id,
      'meta_key'=>'parentId',
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>"rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    The problem now is that all the links are showing on all the posts. What can I do to have the links added by visitors on a specific post to show only on that specific post?

    Any thoughts?

    Posted 14 years ago on Sunday October 17, 2010 | Permalink
  5. you probably need to use one of the WordPress conditionals to specify which posts you want the content to appear on. ex: is_single('17')

    http://codex.wordpress.org/Conditional_Tags

    Posted 14 years ago on Sunday October 17, 2010 | Permalink
  6. Chris
    Member

    Kevin, I've looked into it but I can't see how I could use conditional tags because, for example, is_single('17') uses an integer as a value for a post id, whereas using a custom field to store the post's id will return a different id for every post, a variable. So, how could I use this variable with conditional tags?
    I'm not sure it's possible...

    Any other way I could allow visitors to add links to already published posts? I'm running out of possibilities here... :(

    Posted 14 years ago on Monday October 18, 2010 | Permalink