WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Most Recent Posts Mod
Show the recent posts in multiple columns? (2 posts)

  1. Zavarzin
    Member
    Posted 3 years ago #

    Is there a way to split the recent posts showing up in 2 or 3 or 4 columns?

    http://wordpress.org/extend/plugins/advanced-most-recent-posts-mod/

  2. Kailey (trepmal)
    Volunteer Mod & Reviewer
    Plugin Author

    Posted 3 years ago #

    Open up <a href="http://plugins.trac.wordpress.org/browser/advanced-most-recent-posts-mod/trunk/adv-most-recent.php?rev=380061">adv-most-recent.php</a> and make the following changes:

    (the line numbers I reference are all from the unchanged file)

    Replace line 385, looks like
    $posts = get_posts($query); //get posts
    With this:

    $posts = get_posts($query); //get posts
    $total = count($posts); //using count instead of $shownum in case there are fewer posts
    $cols = 5;
    $rows = ceil($total/$cols);

    $cols should reflect the number of columns you actually want (sorry, I haven't added a nice input field to the widget for this)

    Replace line 392, looks like
    foreach ($posts as $post) {
    With this:

    $c = 0; //li counter
    $x = 1; //ul counter
    foreach ($posts as $post) {

    Replace line 458, looks like
    }// end foreach()
    With this:

    ++$c;
    if ($c%$rows == 0 && $c != $total) {
    	++$x;
    	$postlist .= '</ul><ul class="advanced-recent-posts col-'.$x.' '. $cat_slug .'">';
    }
    }// end foreach()

    And lastly, change lines 465-467 which look like

    echo '<ul class="advanced-recent-posts">' . $postlist . '</ul>';
      else
    return '<ul class="advanced-recent-posts">' . $postlist . '</ul>';

    To this:

    echo '<ul class="advanced-recent-posts col-1">' . $postlist . '</ul>';
    else
      return '<ul class="advanced-recent-posts col-1">' . $postlist . '</ul>';

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic