• Hello on this page in the side bar i have three posts the permalink should bring them to that post.

    $args=array(
    'post_type'=>'characters',
    'post_per_page'=>5,
    'order_by'=>'rand'
    );
    $bookChars = new WP_Query($args);
    
    	echo'<div id="bookChars" class="bookChars">';
    	while ($bookChars->have_posts()):$bookChars->the_post();
    
    		echo'<figure class="bookCharsImgs">';
    		the_post_thumbnail('smallRatio');
    		echo'</figure>';
    		//echo get_permalink($post->ID);
    		echo "<a href='".the_permalink()."'>Link</a>";
    		echo'<h3 class="entry-title">'.get_the_title().'</h3>';
    		echo'<aside class="bookCharsAsides">';
    		the_excerpt();
    
    		echo'</aside>';
    
    	endwhile;
    	echo'</div>';
    wp_reset_query();

    but the links brings back to the about page. not to the actual linked content.

    https://agileart.us/arachnohazard/about/

    How do i fix this so the the user is taken to the appropriate post?
    Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • Remove the_permalink(); function from a tag insert this code get_permalink($post->ID);
    Should be

    echo "<a href='".get_permalink($post->ID)."'>Link</a>";
    Thread Starter agileArt

    (@pdxdaniela)

    Thank you Venugopal!
    That resolved it!
    could you please advise on how to add the title to it?
    I tried a few variant & they didn’t work.

    echo "<a href='".get_permalink($post->ID)."'>the_title();</a>";
    
    echo "<a href='".get_permalink($post->ID)."'>"
    the_title();
    echo "</a>";

    Hi,

    It’s;

    echo '<a href='.get_permalink($post->ID).'>' . the_title() .'</a>';

    Try that ?? should work unless I forgot a period in there some where ??

    Thanks!

    Thread Starter agileArt

    (@pdxdaniela)

    Hello CureWP. that will bring up the title, but as a string. Not a link.

    Ahhh, I see what’s the problem;

    You would do something like this;

    echo '<a href='. the_permalink() .'>' . the_title() .'</a>';

    Hope that helps.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘permalink links to wrong page.’ is closed to new replies.