• is it just me (highly likely at this stage…) or is this impossible:

    while (etc etc)
    $content_str[$i_arr] = the_content();
    endwhile

    so i want to set a content string which is an array with the contents of the_content() function … no such luck? thanks, ryan.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter ryaan

    (@ryaan)

    to better illustrate my problem, i need to do the following (this doesnt work, it just spits things out without assigning the arrays)

    $i_arr = 0;
    if (have_posts()) : while (have_posts()) : the_post();
    $contentID_int[$i_arr] = the_ID();
    $contentTitle_str[$i_arr] = the_title();
    $content_str[$i_arr] = the_content();
    $i_arr = i_arr + 1;
    endwhile; endif;

    any ideas? r.

    Thread Starter ryaan

    (@ryaan)

    i figured it out (hacked) … but for future reference is anyone is searching for a similar solution:

    $i_arr = 0;
    if (have_posts()) : while (have_posts()) : the_post();
    ob_start();
    the_ID();
    $contentID_int[$i_arr] = ob_get_clean();
    ob_start();
    the_title();
    $contentTitle_str[$i_arr] = ob_get_clean();
    ob_start();
    the_content();
    $content_str[$i_arr] = ob_get_clean();
    $i_arr = i_arr + 1;
    endwhile; endif;

    eeeeek.

    If you are programming, look to the actual functions.

    I believe there are get_the_ZZZZZ versions for most of the information. If not, there’s usually an echo vs return param at the end. If not, there’s enough in the function to build it yourself. 😉

    Might I ask WHY you’re trying to re-build data that’s already available to you?

    -d

    Thread Starter ryaan

    (@ryaan)

    hmm, yes i know it was a messy hack.. but i need to get the content, id, content title into arrays, as i am building a ‘pure’ theme with all logic etc just in an includes file, with clean templates.

    as far as i am aware, you need to use The Loop to get the content, but the bit you mentioned about an optional parameter which will return as opposed to echo .. i didnt know that. i will take a look. thanks, r

    Thread Starter ryaan

    (@ryaan)

    MUCH better. i knew there had to be a better way to do it .. thanks again.

    $i_arr = 0;

    if (have_posts()) : while (have_posts()) : the_post();
    $contentID_int[$i_arr] = $postID=$post->ID;;
    $contentTitle_str[$i_arr] = get_the_title();
    $content_str[$i_arr] = get_the_content(“”,FALSE,””);
    $i_arr = i_arr + 1;
    endwhile; endif;

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘setting array to contain content: $content_str[$i_arr] = the_content();’ is closed to new replies.