1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting the title of the previous post in Wordpress

Discussion in 'Web Design' started by dragosdydy, Jul 14, 2013.

  1. dragosdydy

    dragosdydy Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    116
    Likes Received:
    49
    Location:
    Italy
    Hello!
    I just want to create a custom download page in Wordpress that can get the title of the article from where the user came.
    For example i will have the post named "Firefox Version 22.0" and somewhere in the post a Download Link.
    When the user will click the Download Link the custom download page will load and will have the title "Download - [previous post title]" = "Download - Firefox Version 22.0". It will be nice if i could get the excerpt of the post too... :) Thanks!
    I think the both things can be done if i could get the postID number, because i think can get the title and the excerpt if i know the postID :)

    Is there any possibility to do that ? Thanks a lot.
     
  2. SEOWhat

    SEOWhat Regular Member

    Joined:
    Feb 7, 2013
    Messages:
    245
    Likes Received:
    73
    Occupation:
    Web designer, We Developer, SEO
    Location:
    EU
    well, why not add a custom variable e.g. customID inside the link and then add the value <?php echo the_ID(); ?> which is the current page ID value. Now on your download page simply grab that custom value and create a query which will select the post with the ID you passed from customID.

    Here how it should look like <a href="example/download/?customID=<?php echo the_ID(); ?>">Download</a>

    Hope this make sense to you
     
    • Thanks Thanks x 1
    Last edited: Jul 14, 2013
  3. royserpa

    royserpa Jr. VIP Jr. VIP Premium Member

    Joined:
    Sep 28, 2011
    Messages:
    4,657
    Likes Received:
    3,498
    Gender:
    Male
    Occupation:
    Negative Options aka Rebills!
    Location:
    Royserpa
    Home Page:
    An easier solution would be:

    To create a php script that reads the referrer and according to it, the title would be displayed.

    It could be sth like:

    Code:
    <?php
    $referrer = $
     
    • Thanks Thanks x 1
  4. gullsinn

    gullsinn Jr. VIP Jr. VIP Premium Member

    Joined:
    Dec 24, 2009
    Messages:
    2,429
    Likes Received:
    2,210
    Gender:
    Male
    Occupation:
    Jobless :D
    Location:
    Graveyard
    Home Page:
     
    • Thanks Thanks x 1
  5. royserpa

    royserpa Jr. VIP Jr. VIP Premium Member

    Joined:
    Sep 28, 2011
    Messages:
    4,657
    Likes Received:
    3,498
    Gender:
    Male
    Occupation:
    Negative Options aka Rebills!
    Location:
    Royserpa
    Home Page:
     
    • Thanks Thanks x 1
  6. dragosdydy

    dragosdydy Junior Member

    Joined:
    Jan 23, 2012
    Messages:
    116
    Likes Received:
    49
    Location:
    Italy
    Thanks all. I will try the referrer solution! :)
     
  7. royserpa

    royserpa Jr. VIP Jr. VIP Premium Member

    Joined:
    Sep 28, 2011
    Messages:
    4,657
    Likes Received:
    3,498
    Gender:
    Male
    Occupation:
    Negative Options aka Rebills!
    Location:
    Royserpa
    Home Page:
    That will do the trick. Though it's quite exploitable as the referrer can be spoofed.

    If you re doing it for security reasons, then Mysql or databases solutions + php are teh real deal.

    MySQL should be used so that the server stores and retrieve values that can't be altered by the visitors.

    PM me if you would like sth like it :D (Free of charge)
     
    • Thanks Thanks x 1