Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
9.2k views
in Plugins by
On Stackoverflow, answers have:

link | edit

below each answer.

Link points to:
http://stackoverflow.com/a/10472961/913295

There are occasions when it would be useful to share a link to a specific answer. I suppose I can roll my own unless there is an existing solution.

5 Answers

–1 vote
by
edited by

You could use a plugin for this purpose: NoahY's sharing plugin and add a separate link with #post-id. The sharing options appear below each post.

Otherwise, you change the CSS design of the already linked part (link is on "answered" by ..., "commented" by ...) or you use jquery to add some hover effect, like tipsy -> "share this" bubble.

0 votes
by

Added to qa-theme:

        function a_item_main($a_item) {
            // Just inside function
            $link = '<a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '#' . $a_item['raw']['postid'] . '"
            class="qa-form-light-button qa-form-light-button-edit" title="permalink to this answer">link</a>';
            $this->output($link);

            // ...


        function a_list_item($a_item) {
            // Just inside function
            $link = '<a name="#' . $a_item['raw']['postid'] . '" />';
            $this->output($link);

            // ...

See current example here.

I am unable to, without doing more extensive hacking, or figure out what is going on with javascript, to insert the 'link' button to the front of the other form buttons being output in the function form_buttons($form, $columns) because I do not have access to $a_item.

Other option would be to inject $a_item['raw']['postid'] as a hidden field in the form for the specific answer.

At this point, I am looking for guidance from here. What I have at present with the link appearing to the right of the Favorite Icon is not the correct placement.

Thank you :)

by
How can I wrap the code in a code block in the answer form? Like here:
http://www.question2answer.org/qa/14901/how-to-change-link-of-my-updates-qa-page-php
by
Found a way to create a Permalink for each answer and have it appear to the left of other answer 'buttons'.

Edited qa-include/qa-page-question-view.php

In function qa_page_q_answer_view(...

Above:
            if ($answer['editbutton'])

Insert:

            $buttons['link']=array(
                'answerid' => $answerid,
            );

Added to:

qa-theme.php

        function form_buttons(...

Above:
                foreach ($form['buttons'] as $key => $button) {...

Insert:

                if (array_key_exists('link', $form['buttons'])) {
                    $answerid = $form['buttons']['link']['answerid'];
                    $link = '<a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REDIRECT_URL'] . "?show=$answerid#a$answerid " . '" .
                    class="qa-form-light-button qa-form-light-button-edit" title="permalink to this answer">link</a>';
                    $this->output($link);
                }

Look at an example of the placement of answer permalinks here:

http://www.noblood.org/answers/137/what-should-i-know-about-blood-transfusions#.T7L5iMVgApk

Please let us know if there is a more elegant solution.
0 votes
by

Your answer is partially correct, larryeitel, but it will not work for questions where the answers are split over multiple pages. For example this link does not work without the show part: http://www.question2answer.org/qa/8750/now-taking-requests-for-question2answer-1-5?show=8820#a8820

Also, the # anchor isn't reall the right one to use, it should have an 'a' at the start. (For some reason you have <a name="138"></a> several times in the HTML which is invalid anyway.)

The link should look like: example.com/123/question-title?show=N#aN

...where '123' is the question ID and 'N' is the answer ID.

 

by
Ok, I implemented: ?show=N#aN

I looks like <a name="N"></a> is being output by Q2A and WithOut prepending 'a'.

Thank you for your input.
by
The <a name="N"></a> thing is output by Q2A, but only once for each answer. I noticed on your site it appears multiple times for each answer for some reason. It's invalid to have multiple elements with the same name (otherwise, how would it know which answer to jump to when you link to #123?)
by
I found a better solution and submitted a new answer. This is a perfect example of why it would be nice to have permalinks because I would be able to reference directly the new answer that I submitted.
0 votes
by
Found a way to create a Permalink for each answer and have it appear to the left of other answer 'buttons'.

Edited qa-include/qa-page-question-view.php

In function qa_page_q_answer_view(...

Above:
            if ($answer['editbutton'])

Insert:

            $buttons['link']=array(
                'answerid' => $answerid,
            );

Added to:

qa-theme.php

        function form_buttons(...

Above:
                foreach ($form['buttons'] as $key => $button) {...

Insert:

                if (array_key_exists('link', $form['buttons'])) {
                    $answerid = $form['buttons']['link']['answerid'];
                    $link = '<a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REDIRECT_URL'] . "?show=$answerid#a$answerid " . '" .
                    class="qa-form-light-button qa-form-light-button-edit" title="permalink to this answer">link</a>';
                    $this->output($link);
                }

Look at an example of the placement of answer permalinks here:

http://www.noblood.org/answers/137/what-should-i-know-about-blood-transfusions#.T7L5iMVgApk

Please let us know if there is a more elegant solution.
by
Larry, it would be nothing else then fair if You would respect the rules and add the link to question2answer.org again.
by
I would be happy to repost again. In what way does my post violate the rules?
by
Larry, Your post is fine, and everything else as well. I still thought that one must have a link back to q2a on his site, but things changed meanwhile, so I ask to excuse me please. Here You can read about, but it was my fault..
http://www.question2answer.org/qa/7549/do-we-need-to-keep-the-licence-on-our-website-we-use-this-script
by
No worries. I use a variety of add-ins that if I included a ref to each one it could become quite busy. I do however try to actively support through other means.
+1 vote
by
This is already implemented, perhaps not obviously.

The 'answered' word by each answer gives a link directly to that answer.

Similarly for 'commented'.
...