Jump to content

retrieve url from a post to set in a href button


Vinz

Recommended Posts

Hi everyone!

i hope someone here can help me.

i use worpdress, and i need to get a url from a post to set into href button dynamically.

i don't know if i can achieve this only with html or mixed with some php or js

let me explain it further:

i have a listing site which shows every listing in a grid style. the grid elements are clickable which redirects to the single listing post.

but i added a button under each grid element, the href url is not known in advance, how can i retrieve that permalink for each single listing page to dynamically populate the href in a html button?

 

for now i have icon with empty href

<a href="#">[27-icon icon="fa fa-arrow-alt-circle-right"]</a>

i was reading wordpress codex

and there are php functions like:

<?php get_post_permalink( $id, $leavename, $sample ); ?>

get_permalink( int|WP_Post $post, bool $leavename = false )

get_post_class( string|string[] $class = '', int|WP_Post $post_id = null )

i'm not a developer, but i understand a bit what i'm reading in the php code, if i understand it good i could use css class maybe to point to the grid element and then use get function to auto retrieve the url of a post and populate my button href ???

or is there another easy way ?

If someone could explain me how to do this as i'm sure its used a lot on websites.

 

Thanks to help me

 

 

 

Edited by Vinz
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.