Friday, November 25, 2022
HomeWordPress Developmentphp - Including commas between put up titles on an archive web...

php – Including commas between put up titles on an archive web page?


I’m engaged on my archive.php, which is utilized by a number of completely different customized put up varieties.

On the archive pages, I would love put up titles to show with commas between them (however not after the ultimate put up), e.g.:

Title 1, Title 2, Title 3

That is the code I presently have, however my if assertion is not working. I am very new to PHP and WP, so any assist may be very a lot appreciated.

<?php
    if ( have_posts() ) {
        whereas ( have_posts() ) {
            the_post();
            echo '<a href="', the_permalink(), '">', the_title(), '</a>';
            if ((current_post) < (post_count-1)) {
                echo ', ';
            }
        }
    }

    wp_reset_postdata();

?>

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments