It does what I want it to do, displays a certain category of posts in a column on a page. Right now its just the title, but I want to link that title and the permalink section isnt working, or rather the href.
[php]
// The Query
$the_query = new WP_Query( 'cat=3' );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul style="list-style:none;">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . '<a href="the_permalink();">' . get_the_title() . '[/a]'. '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
[/php]
It links to subdomain.domain.com/site/the_permalink(); instead pulling the permalink for that post and linking to it.
the_permalink(); return to echo your link.
You need to return only string. For this you can use
get_the_permalink($post->ID);
Because your permalink function is inside of echo function.
When you enter the a-tag you start with HTML, if you close it you change to BBCode.
Fatih is right, you need to use
get_permalink
function. Since you’re inside the loop, you don’t need to specify the parameter ($post->ID
).Also, you need to switch back to PHP (that is your main problem) as you did with
get_the_title
function. There are multiple syntax issues with your code (brackets!).The line should go like this:
Learn the difference between
echo
andreturn
in (not only) PHP functions!