lilqhgal
Member
Posted 4 weeks ago #
I'm trying to hard-code the permalink into a php call but for the life of me can't find the correct format to use. I'm echoing a string of html so obviously can't simply stick <?php the_permalink() ?> in there. It has to look something like $link = get_post_meta($post->ID, 'the_permalink', true); but that's not working for me. Can anyone point me in the right direction? Thanks!
lilqhgal
Member
Posted 4 weeks ago #
Thanks esmi, but I already read thru that and it's not helping. I should clarify my issue... I'm trying to create a link inside some php that outputs some html via the echo command from a category level page. Anywhere else in the template file, I can simply use <?php the_permalink() ? but putting that in my echo line breaks the php. I need a way to grab the permalink and stick it into a variable so it won't break the echo line. Here's the main chunk of my code below:
<?php //if custom field is present, formulate and display html from meta value
$proj_img_thumb = get_post_meta($post->ID, 'proj_img_thumb', true);
$link = get_post_meta($post->ID, 'the_permalink', true);
if ($proj_img_thumb){
echo '<a href="'.$link.'"><img src="'.$proj_img_thumb .'" /></a>';
}
?>
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">Learn more about <?php the_title(); ?>.</a>
Is this link meant to the current post's slug or a url from a custom field attached to the current post?
lilqhgal
Member
Posted 4 weeks ago #
It would be to link to the post's slug. I am no programmer (I know enough to break stuff but not enough to fix LOL) so I copied what was working (the custom field php stuff) and tried to modify it for my needs. Obviously I screwed it up. *sheepish grin*
Basically .... I need to make the output of <?php the_permalink() ?> into my variable $link
Thanks so far!
get_permalink: Returns the permalink to a post for use in PHP. It does NOT display the permalink and can be used outside of The Loop.
Seems ideal for your use.
lilqhgal
Member
Posted 4 weeks ago #
I had to try a few different things but what ended up working was:
$permalink = get_permalink($post->ID);
Thanks for the nudge in the right direction (and being patient!) esmi!