Hi there,

I am trying to have a PHP variable in my link, so that my final link would look like:

example.com/eformat/variable-goes-here.rtf

I've managed to get example.com/variable-goes-here but no more than that. I really don't know PHP very well, so help would be greatly appreciated. Please excuse my beginner level. Thanks! :D

<?php $eformat = $post–>post_name; echo "<a href=\"$eformat\">Download this blog post in eFormat (.rtf)</a>" ?>

echo "<a href='".$eformat."'>Download this blog post in eFormat (.rtf)</a>";

Well, I've tried your code within my code, but all it gives me is www.example.com/eformat/.rtf

What to do? =(

<?php $eformat = $post–>post_name; echo "<a href='".$eformat.".rtf'>Download this blog post in eFormat (.rtf)</a>" ?>

i was tested. its working fine. once check echo $eformet;
<?php $eformat = "test"; echo "<a href='".$eformat.".rtf'>Download this blog post in eFormat (.rtf)</a>" ?>

remove slash after file name which comes from $post–>post_name;

@Kalpana: You are right, it works when the variable is just a text like "test"... but I want to use a Wordpress variable, namely $post->post_name which should give me the slug of any blog post.

@Shanti: What slash are we talking about? Are you saying that the post slug automatically includes a trailing slash, which is why it doesn't work? If so, do you know of a way to fix that or of an alternative Wordpress variable?

Wow, two solutions have been found on two other forums. :) And here I was trying to figure out even one solution by myself.

<?php echo "<a href='eformat/{$post->post_name}.rtf'>Download this blog post in eFormat (.rtf)</a>" ?>
<?php $var = $post->post_name; echo '<a href="eformat/' . $var . '.rtf">Download this blog post in eFormat (.rtf)</a>'; ?>

Thanks everyone for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.