Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthormista3
    • CommentTimeJul 3rd 2006 edited
     permalink
    Hey folks,

    I think someone with php knowledge might be able to help me with this... hopefully :)

    I'm trying to modify a plugin I found, to output the entire contents of child pages onto their parent page....

    But I've got stuck with one part - splitting this output into two divs, a left and a right column basically. I want a second column to start when you get halfway through the child pages, but I'm bad at php and don't get the foreach command :(

    Also, I'm also not sure if my $postcount variable is working as it should...


    $parent_title = $page->post_title;
    // See if there are any subpages of this page
    $subpages = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = '$parent_id'");
    if( $subpages > 0 ) {
    // Grab the HTML formatted list of subpages
    $junk .= wp_list_pages("child_of=$parent_id&depth=$depth&sort_column=menu_order&echo=".(!$return)."&title_li=0");
    //Break them into an array of individual lines
    $lines = explode("\n", $junk);
    $postcount = 0;
    echo('<div id="leftcol">');
    // Step through the lines and ...
    foreach ($lines as $value) {
    echo $postcount;
    // Isolate just the post-slug-title
    $temp = explode("/\" title=\"", $value);
    $temptwo = explode("/", $temp[0]);
    $size = count($temptwo)-1;
    $getme = trim($temptwo[$size]);
    $name_or_id = "post_name = '$getme' AND";
    // Here we grab post data from the database
    $post = $wpdb->get_row("SELECT * FROM $table WHERE $name_or_id post_date <= '$now' AND ($query_suffix) ORDER BY post_date DESC LIMIT 1");
    // Display the image from the custom meta field
    $currentpostid = $post->ID;
    $postmeta = get_post_meta($currentpostid, 'prepic', true);
    echo("<img class='mugshot' src='".$blogurl."http://www.e-tv-interactive.com/new/".$postmeta."' />");
    // And grab and display the actual title while we are in the neighborhood
    $grab = explode("\"", $temp[1]);
    echo("<h3>$grab[0]</h3>");
    // And echo the post content
    echo("<p>");
    echo($post->post_content);
    echo("</p>");
    echo("\n");
    // Once we are halfway through the child pages, start the second column
    if ($postcount == $size/2) {
    echo('</div>');
    echo('<div id="rightcol">');
    $postcount++;
    }
    }
    echo('</div>');
    }
  1.  permalink
    Maybe the problem is that the $postcount is incremented inside the $postcount == $size/2 condition? Since the $postcount is always zero, it'll never increment, thus never splitting the column.
    • CommentAuthormista3
    • CommentTimeJul 4th 2006
     permalink
    So is there any way I can make postcount increase by 1 for each loop of the foreach?
  2.  permalink
    Just move the $postcount++; line out of the condition, before it or after it, like so:

    if ($postcount == $size/2) {
    echo('</div>');
    echo('<div id="rightcol">');
    }
    $postcount++;
    • CommentAuthormista3
    • CommentTimeJul 4th 2006
     permalink
    doh! thanks
    • CommentAuthormista3
    • CommentTimeJul 4th 2006
     permalink
    it works, :) :) :)
Add your comments
    Username Password
  • Format comments as (Help)