• Simple questions, undoubtably complicated answer.

    Is there, or does anyone know how, to make a function which outputs an comma seperated list of post titles in singlequotation marks from a category of my choosing. (just post titles, no links, no formatting nothin – literally just the titles)

    for example I would put get_the_titles(cat=4) and it would output

    ‘post title 1’, ‘post title 2’, ‘post title 3’

    thanks,

Viewing 3 replies - 1 through 3 (of 3 total)
  • This should do what you want:

    $cat = 65; // The category id to show
    $args = array(
      'numberposts' => -1,
      'category' => $cat
    );
    $myposts = get_posts($args);
    $list = '';
    $sep = '';
    foreach ($myposts as $post) {
      $list .= $sep . "'$post->post_title'";
      $sep = ', ';
    }
    echo "<p>$list</p>";
    Thread Starter zandercent

    (@zandercent)

    You, my friend, are a legend – thank you so much for your help.

    Glad it worked! Now, please use the dropdown on the right to mark this topic ‘Resolved’.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘comma seperated list of post names in a category’ is closed to new replies.