Community Forums › Forums › Archived Forums › Design Tips and Tricks › $get_permalink to another post (PHP question)
- This topic has 5 replies, 2 voices, and was last updated 11 years, 2 months ago by
Chris Moore.
-
AuthorPosts
-
December 29, 2013 at 2:40 pm #81907
Ben @ Inbound Creative
MemberHi guys and girls,
I'm wracking my head around this one and don't seem to be getting anywhere.
I've created a more posts section at the bottom of one of my post templates.
I'm using Nathan Rice's Post Templates plugin to achieve the use of post templates.
Everything is working fine except for the permalinks for the more posts section.
I want to call the relevant post's permalink in PHP without needing to code it manually each time I add a new case study.
I had thought the way to get around this was to add in the following code:
$get_permalink($post->ID)
However, this stops the rest of the DIV being called resulting in a blank space.
The full code for the section is below:
<div class="more-clients"> <h1>More Success Stories</h1> <?php $cat_id = 46; //the certain category ID $latest_cat_post = new WP_Query( array('posts_per_page' => 12, 'category__in' => array($cat_id))); if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post(); ?> <a href="<?php $get_permalink ?>"><div class="clients-more-box"> <?php $img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) ); printf( $img ); ?> <div class="clients-more-box-text"> <p class="clientsmore-client"><?php echo get_post_meta($post->ID, 'Company', true);?></p> <p class="clientsmore-subheader"><?php the_subheading(); ?></p> </div> </div></a> <?php endwhile; endif; ?> </div>
The page is currently behind a coming soon wall, but I can remove that if you need me to.
Thanks in advance
December 29, 2013 at 3:27 pm #81916Chris Moore
MemberI'm not that adept at PHP, but I wanna see if this works. 😉
Try this:
href="<?php '. get_permalink() .'?>"
Or this?
href='<?php echo get_permalink($post->ID); ?>'
Resepctfully, Chris Moore
Web Dev, CSS Hacks, & Biz Consulting @ MooreCreativeIdeas.com / Blogging @ ReflectOnThis.comDecember 29, 2013 at 4:10 pm #81923Ben @ Inbound Creative
MemberSecond one worked. I had a horrible gut feeling it was going to be something like echoing the string.
Thanks Chris!
December 29, 2013 at 4:11 pm #81924Chris Moore
MemberNo way!!! Haha... Victory!
You're welcome.
Can you try this though:
href="<?php echo get_permalink($post->ID); ?>"
With the double instead of single quotes... Just curious.
Resepctfully, Chris Moore
Web Dev, CSS Hacks, & Biz Consulting @ MooreCreativeIdeas.com / Blogging @ ReflectOnThis.comDecember 29, 2013 at 4:56 pm #81927Ben @ Inbound Creative
MemberI put it in double quotes from the off. Just realised you'd put it in single quotes the first time round. I'd copy and pasted the bit between the <>s.
And haha. That's exactly the same expression I had when it worked.
Everytime you think you've got your head around PHP, it throws you another curveball.
December 29, 2013 at 10:20 pm #81966Chris Moore
MemberAwesome man! Glad it worked out. Looks like this one is "Resolved"! 🙂
Resepctfully, Chris Moore
Web Dev, CSS Hacks, & Biz Consulting @ MooreCreativeIdeas.com / Blogging @ ReflectOnThis.com -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.