- This topic has 9 replies, 2 voices, and was last updated 1 year ago by
David.
-
AuthorPosts
-
April 5, 2020 at 3:48 am #1227114
Tim
How do I get the link to a post so that I can put it in the listing’s
<img>
<figure class="publication-header-media"> <?php $cover = get_field('cover'); $size = 'full'; // (thumbnail, medium, large, full or custom size) if( $cover ) { echo wp_get_attachment_image( $cover, $size ); } ?> </figure>
April 5, 2020 at 7:32 am #1227268David
StaffCustomer SupportHi there,
i assume the link will be from an ACF field, so you’ll need to create a variable to get the url. In this example we’ll call it
$pub_link
Then you can echo the anchor tags around your image like so:
echo '<a href="' . $pub_link .'">' . wp_get_attachment_image( $cover, $size ) . '</a>';
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 6, 2020 at 8:28 pm #1229293Tim
Hi David
I don’t think I’ve explained well.
wpsp displays the H2 with a link to its post.
I want to do the same with the
<figure>
or<img>
in the listing. wpsp does this for me with the Featured Image, but I’m not using the featured image.It doesn’t make sense to me to do this with an ACF field which would require the user to remember to get the URL and enter it which may lead to user error.
Should I not use WP’s inbuilt fields such as
get_permalink
or similar ?Or could I get the link the same way wpsp is getting the link to add to the
H2
in the listing ?Thanks
April 7, 2020 at 4:30 am #1229664David
StaffCustomer SupportOK – then you can do this to get the link:
$pub_link = esc_url( get_permalink() );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 7, 2020 at 6:05 pm #1230593Tim
Nice.
Followup question; I understand the quotes are for escaping, but what do the dots (periods) represent?
' . $pub_link .'
April 8, 2020 at 1:35 am #1230851David
StaffCustomer SupportIt means to concatenate 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 8, 2020 at 9:54 pm #1232060Tim
Hi David
But is there anything to concantenate there?
Isn’t it just a single string of text that is escaped then escaped?
April 9, 2020 at 5:12 am #1232385David
StaffCustomer SupportPHP methods are many:
https://stackoverflow.com/a/5605970there are some things concatenate can do other methods cant – such as function calls or methods – in this instance its not required – so just my preference for readability and consistency.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 9, 2020 at 7:43 pm #1233417Tim
Gotcha
April 10, 2020 at 1:16 am #1233576David
StaffCustomer SupportYou’re welcome
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.