Getting the title of the previous post in Wordpress

dragosdydy

Junior Member
Joined
Jan 23, 2012
Messages
116
Reaction score
50
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.
 
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
 
Last edited:
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 = $
 
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 = $[/QUOTE]

This will not be easier for him, I guess.
 
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 = $[/QUOTE]

It seems code wasnt entered correctly, though, here's the full code:

[code]
<?php
$referrer = $_SERVER['HTTP_REFERRER'] //This basically gets the referrer of the visitor
$link1 = "http://www.google.com" //Let's say that the visitor comes from google

if { $referrer == $link1 } { //This compares if referrer is Google.com
    echo "Visitor comes from Google"; // It prints that visitor comes from Google
    } else {
    echo "Visitor comes from Nowhere"; // If no referrer, it prints Visitor comes from Nowhere
    }

?>

This will not be easier for him, I guess.

Sorry man, it appears whole code didn't appear. Please check what I posted above thiq quote :D
 
Thanks all. I will try the referrer solution! :)
 
Thanks all. I will try the referrer solution! :)

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)
 
Back
Top