1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to create a link for post comments?

Discussion in 'PHP' started by Mustafa Baysal, May 23, 2017.

  1. #1
    May be this is an easy question for most but i couldn't do it. I just want to add a link an my Post Page (wordpress) and when a visitor clicks it he or she must go the comments part of that page.

    Something like this:

    <a href="mywebsite. com/sample-post/#comments">
    Leave a Comment </a>

    But, i will add this code to the single-content.php so what should i write instead of this: mywebsite. com/sample-post/

    So when i add the code to single.php file once, then it will take visitors to the comments section of every single page..

    Thanks.
     
    Mustafa Baysal, May 23, 2017 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    I'm confused... why don't you just do <a href="#comments">Leave a comment</a>? If you're gonna use this on the specific page the user is already on, why use a full link, when just the #comments works?

    If you want someone to be able to go to the comments-section for specific pages from other pages, that's a different story.
     
    PoPSiCLe, May 23, 2017 IP
  3. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #3
    Set the id attribute of your <div> element containing the comments as as comments
    Then for your button, use something like this: <a href="#comments" class="btnScrollToComments">Goto Comments</a>

    And in jQuery code:

    
    $(function(){
      $(".btnScrollToComments").click(function() {   
          $('html, body').animate({
              scrollTop: $("#comments").offset().top
          }, 2000);
      });
    });
    Code (JavaScript):
    This will give you a smooth effect of scrolling.

    Hope this helps.
     
    akhileshbc, May 23, 2017 IP
  4. Mustafa Baysal

    Mustafa Baysal Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    That's almost worked. Thank you. But have a little problem.
    The page that i will use this code is the AMP page. And i want visitors to go to the non-AMP page. So your code worked but still sending the visitor to the same AMP Page..

    So what must do for sending them to the non/AMP page of the page?

    Ps: I am using this code on AMP content-single.php
     
    Mustafa Baysal, May 23, 2017 IP
  5. Mustafa Baysal

    Mustafa Baysal Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    Correcting and simpling my question: how to direct my AMP page to Non-AMP page? Which code will be useful?
     
    Mustafa Baysal, Jun 3, 2017 IP
  6. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #6
    When you mentioned "AMP", are you referring to Accelerated Mobile Page? Or something else?
     
    akhileshbc, Jun 3, 2017 IP
  7. Mustafa Baysal

    Mustafa Baysal Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    Yes i mean accelareted mobile pages.
     
    Mustafa Baysal, Jun 3, 2017 IP