Ok bear with me I am new to wordpress. I am using the below code to grab the title of the posts but it is not working what am I doing wrong?
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?
the_title();
} // end while
} // end if
?>
You are mixing two different php syntax.
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
// inside the loop here
<?php the_title(); ?>
<?php endwhile; ?> // end while
<?php endif; ?> // endif
Instead of using curly braces for control structures you can use the alternative syntax . This helps to make the code more readable in templates where you are using a mix of php and HTML
Have a look at your loop, it doesn't look like it's formatted correctly. It could look something like this
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
the_title();
} // end while
} // end if
?>
Check out the docs for more info on the_loop https://codex.wordpress.org/The_Loop
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.