Erez-BegDev
Erez-BegDev

Reputation: 7

Wordpress - CPT Archive Template -> the_title(); & the_shortlink();

1st time opening a post and in desperate need of some help.

This question might be very simple (most likely) but I can't figure it out been trying for the past 2 days.

So I've created a new Custom Post Type in my wordpress site and am in the middle of creating a template for the Archive where you'll see all the posts that have been created.

Here's the problem I want to make the title of the post to show (which is working fine) but also be a link to the post itself. I know there's the_shortlink(); which works just fine but I want the title of the post itself to be the link.

Under it will be some of the text that is written in the body kinda like a preview of whats inside the post. From what I understand I can use the_excerpt(); please let me know if this is wrong too.

//Some CSS this is not important atm
    <div class="aa-div">
<?
        if(have_posts()) : while(have_posts()) : the_post();
        the_title();
        the_shortlink();
        echo '<div class="entry-content">';
        the_content();
        echo '</div>';
    endwhile; endif; ?>
    </div>

Hope you have a great day and a happy new year.

Upvotes: 0

Views: 191

Answers (3)

Brijesh Dhanani
Brijesh Dhanani

Reputation: 886

You can use following code

the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );

instead of

the_title();

Upvotes: 0

Cafer Elgin
Cafer Elgin

Reputation: 423

You can use html element and link the title to the permalink of the post:

<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>

Upvotes: 1

saifur
saifur

Reputation: 637

use get_post_permalink function.

<?php echo get_post_permalink() ?>

Upvotes: 0

Related Questions