• I’m doing the following bit of trickery to allow for a file download of the same name as the post title:

    <a href="/files/<?php the_title(); ?>.zip">Download <?php the_title(); ?></a>

    The obvious problem is that it inserts a %20 where spaces are. I would prefer to have the filename match the %postname%, that is “post-title” becomes “post-title.zip”. However, there’s no “the_postname”, and ‘the_permalink’ gives me, well, the whole link. I’ve looked through the codex, and nothing seems to do it.
    Any ideas?

Viewing 5 replies - 1 through 5 (of 5 total)
  • If this is in The Loop, you can simply go right to the variable: $post->post_name.

    Thread Starter Arlo

    (@arlo)

    It is in the loop. I’m not clear on the syntax though..I dug through the codex, but nothing seems to work (sorry, I’m partially php newb…)

    I tried variations of this: <?php $post->post_name() ?> but no go…

    You’ll need to echo it. <a href="/files/<?php echo $post->post_name;?>.zip">Download <?php echo $post->post_name; ?></a>

    You could also do it by post ID instead of name… I’ve done that before, works well.

    -d

    Thread Starter Arlo

    (@arlo)

    ColdForged worked like a charm, thanks!
    David -yeah, post_id works, but it doesn’t make for pretty filenames ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Trying to extract “postname”’ is closed to new replies.