the_permalink little problem
-
Hello guys! I’ve been playing a bit with PHP and WP code to display a definite number of post from particular categories in index.php. And this is what I got so far:
<?php $args = array( 'cat' => 10, 'posts_per_page' => 3 ); $query = new WP_Query( $args ); while($query->have_posts()): $query->next_post(); $id = $query->post->ID; echo '<h2>'; echo '<a href="'. the_permalink() .'">'. get_the_title($id) .'</a>'; echo '</h2>'; echo the_excerpt(); endwhile; ?>
Everything seems to be working fine, except for a little detail related to the post title and it’s link to the full post. So this is what I got in return when the PHP is processed:
<div id="noticia"> <h2>https://www.url.com/post-slug<a href="?preview=1&template=la97&stylesheet=la97">Post Title</a></h2>A lot of text representing the excerpt<a href="https://www.url.com/post-slug?preview=1&template=la97&stylesheet=la97">[...]</a> </div>
As you can see, I cannot find the way to get the post link in the proper place. It’s being displayed outside of the link tags, so it generates a not-working link instead.
Any ideas? :S
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘the_permalink little problem’ is closed to new replies.