WordPress – get link to a post

I want to display the thumbnail of a post. If the user clicks the thumbnail he gets directed to that post. But when clicking it I get a 403 ERROR. I’m new to php what is wrong?

PHP

<?php
query_posts('cat=5');
while (have_posts()) : the_post();

 the_title();

echo '<a href="<?php the_permalink();?>">';
    the_post_thumbnail();
echo '</a>';
endwhile;
?>

Related posts

Leave a Reply

5 comments

  1. <?php the_permalink();?>
    

    Displays the URL for the permalink to the post currently being processed in The Loop. This tag must be within The Loop, and is generally used to display the permalink for each post, when the posts are being displayed. Since this template tag is limited to displaying the permalink for the post that is being processed, you cannot use it to display the permalink to an arbitrary post on your weblog. Refer to get_permalink() if you want to get the permalink for a post, given its unique post id.

    <?php echo get_permalink(1); ?>
    

    http://codex.wordpress.org/Function_Reference/the_permalink

  2. just replace your code

    echo '<a href="<?php the_permalink();?>">';
    

    TO :

    <a href="<?= the_permalink();?>">
    

    your code will be :

    <?php
    query_posts('cat=5');
    while (have_posts()) : the_post();
    
     the_title();
    ?>
    <a href="<?= the_permalink();?>"><?= the_post_thumbnail(); ?></a>
    <?php
    endwhile;
    ?>
    
  3. I think it may be your syntax.

    Try changing: echo '<a href="<?php the_permalink();?>">';

    to: echo '<a href="';
    the_permalink();
    echo '"';

    The reason being that you are trying to reinitialize php even though you must have already started the syntax if you are using echo. So you do not need <?php ?>

    Here is another forum for reference.

  4. You have mistake in this section:

    echo '<a href="<?php the_permalink();?>">';
    

    Replace that line on this:

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

    And don’t use short echo <?=...?> , it can be turned off by your hosting provider.

    the_permalink() function already have echo, so you should not put second echo.

    function the_permalink() {
        /**
         * Filter the display of the permalink for the current post.
         *
         * @since 1.5.0
         *
         * @param string $permalink The permalink for the current post.
         */
        echo esc_url( apply_filters( 'the_permalink', get_permalink() ) );
    }