$get_permalink to another post (PHP question)

Community Forums Forums Design Tips and Tricks $get_permalink to another post (PHP question)

This topic is: resolved

This topic contains 5 replies, has 2 voices, and was last updated by  Chris Moore 10 months, 3 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #81907

    Ben @ Advice Media
    Participant
    Post count: 182

    Hi 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


    #81916

    Chris Moore
    Participant
    Post count: 136

    I’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.com

    #81923

    Ben @ Advice Media
    Participant
    Post count: 182

    Second one worked. I had a horrible gut feeling it was going to be something like echoing the string.

    Thanks Chris!


    #81924

    Chris Moore
    Participant
    Post count: 136

    No 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.com

    #81927

    Ben @ Advice Media
    Participant
    Post count: 182

    I 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.


    #81966

    Chris Moore
    Participant
    Post count: 136

    Awesome 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

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.