0

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>" ?>
3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by Feabionsu
0

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

Edited by muralikalpana: n/a

0

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>" ?>
0

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>" ?>

0

@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?

0

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!

Edited by Feabionsu: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.