Can the sidebar blocks that show recent items be altered to show more or less posts ala what can be done for nodes on the main page? I find that 'recent comments' takes up a lot of space considering they have the dates attached.

If the dates and comment teasers had their own classes specified I could turn them via display: none in css, but that would be a stopgap solution. Anyway, I'm unable to find anything on drupal via the search engine or google, sorry if this has been asked before and I missed it.

...using 4.5.

Comments

carlmcdade’s picture

This has been bugging me also.

I can't find anyway of editing the block contents of blocks created by Drupal. I had thought I had seen a confuguration that lets you choose the number of entries but it was on the news aggregator. The others have no settings that I can see.
---------------------------
proof that Drupal will work on PHP5
www.hivemindz.com
www.fireorb.org
__________________________
Carl McDade
Information Technology Consult
Team Macromedia

freyquency’s picture

ah. That's right. That explains a little of why I've been pulling my hair out (um if it weren't shaved) trying to find it. I know about the aggregator controls though. The aggregator and thinking that it was there in the RC a while back created a 'ghost' in my mind - i've spent probably hours looking around the admin areas and tabs looking for controls that weren't there!

I can't imagine it would be hard take the control from the aggregator out and replace it with a more generic version in the block admin area (in theory, cos i don' t know how), right?

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Erik Mallinson
coacalina.org music art geekery
The AIR LOC library of congress community.
[][][][][][][][][][][][][][][][][][][][][][][][][][][][]

carlmcdade’s picture

I found the comment_block hook in comment.module and hard coded (changed the SQL limit to 5) it to a lesser amount. This should have been something added to the core functions when the block lists were created. It does not apply to all blocks like the login. But it would still be nice to be able to adjust even those.

/**
 * Implementation of hook_block().
 *
 * Generates a block with the most recent comments.
 */
function comment_block($op = 'list', $delta = 0) {
  if ($op == 'list') {
    $blocks[0]['info'] = t('Recent comments');
    return $blocks;
  }
  else if (user_access('access comments')) {
    $result = db_query_range('SELECT * FROM {comments} WHERE status = 0 ORDER BY timestamp DESC', 0, 5);
    $items = array();
    while ($comment = db_fetch_object($result)) {
      $items[] = l($comment->subject, 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid) .'<br />'. t('%time ago', array('%time' => format_interval(time() - $comment->timestamp)));
    }

    $block['subject'] = t('Recent comments');
    $block['content'] = theme('item_list', $items);
    return $block;
  }
}

---------------------------
proof that Drupal will work on PHP5
www.hivemindz.com
www.fireorb.org
__________________________
Carl McDade
Information Technology Consult
Team Macromedia

yelvington’s picture

Adjustable recent blog posts|comments limits in the admin->settings would be a very good thing. Especially for those of us who have been looking there and not finding them. :-)

Has this been entered as a feature request?

Cryssli@www.cryss.net’s picture

Total agreement! A option would be superb!
I also spend hours of searching by myself.

shoe’s picture

I tried to change the default 10 to 5 and the site died had to change it back I did try 5 and 05 made no difference.

oc’s picture

The code you modified took care of comment blocks, but to change blog blocks you need to instead modify the call to db_query_range that appears in blog.module. The name of the function is:

blog_block

/**
 * Implementation of hook_block().
 *
 * Displays the most recent 10 blog titles.
 */
function blog_block($op = 'list', $delta = 0) {
  global $user;
  if ($op == 'list') {
    $block[0]['info'] = t('Recent blog posts');
    return $block;
  }
  else if ($op == 'view') {
    if (user_access('access content')) {
      $block['content'] = node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {no\
de} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 5));
      $block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blo\
g entries.'))) .'</div>';
      $block['subject'] = t('Recent blog posts');
    }
    return $block;
  }
}
mwoodwar’s picture

Well, I've been trying most of the day to get a good 'recent comments' section going.

I tried the code above, and got an error messge:
Fatal error: Cannot redeclare comment_block() (previously declared in /home/watertow/public_html/modules/comment.module:161) in /home/watertow/public_html/includes/common.inc(1841) : eval()'d code on line 7

Now I can't get into my site at all...??? Can I correct this somehow without wiping everything out?

Mark

guusbosman’s picture

I've submitted a patch against 5.1 that allows the site administrator to configure the amount of recent comments shown in the recent comments block: http://drupal.org/node/81931

jakeg’s picture

This should be a feature. In block settings you should be able to change the number of comments.

patrickharris’s picture

Or if you have to dig into the code to do it, it should be described in the handbook. I wish we had documentation as good as WordPress.

likoma’s picture

In comment.module (v. 4.6.2, lines 167-170), I found the following:

    $result = db_query_range(db_rewrite_sql('SELECT c.nid, c.* FROM {comments} c WHERE c.status = 0 ORDER BY c.timestamp DESC', 'c'), 0, 10);
    $items = array();
    while ($comment = db_fetch_object($result)) {
      $items[] = l($comment->subject, 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid) .'<br />'. t('%time ago', array('%time' => format_interval(time() - $comment->timestamp)));

I changed the 10 to a 5 and also took out the timestamp part so it now just lists the past 5 comments and no date/time.

    $result = db_query_range(db_rewrite_sql('SELECT c.nid, c.* FROM {comments} c WHERE c.status = 0 ORDER BY c.timestamp DESC', 'c'), 0, 5);
    $items = array();
    while ($comment = db_fetch_object($result)) {
      $items[] = l($comment->subject, 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid);
    }
jazzylee77’s picture

excellent, just what I was looking for!

ok, looks like I picked up an extra } doing a quick replace. This works fine otherwise.

ideaoforder’s picture

I couldn't tell you why the developers didn't do this in the first place... but if you replace the code for the last function in blog.module with the following two, you can adjust the settings yourself (and your users/moderators/admins can too if you happen to be the site webmaster):

/**
 * Implementation of hook_block().
 *
 * Displays the most recent 10 blog titles.
 */
function blog_block($op = 'list', $delta = 0) {
  global $user;

	// Get the max number of posts to display
  $limitnum = variable_get("blog_maxdisp", 10);

  if ($op == 'list') {
    $block[0]['info'] = t('Recent blog posts');
    return $block;
  }
  else if ($op == 'view') {
    if (user_access('access content')) {
      $block['content'] = node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, $limitnum));
      $block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
      $block['subject'] = t('Recent blog posts');
    }
    return $block;
  }
}

function blog_settings() {
  // only administrators can access this function
  if (!user_access('access administration pages')) {
    return message_access();
  }
  $output .= form_textfield(t("Maximum number of posts"), "blog_maxdisp",
             variable_get("blog_maxdisp", "10"), 2, 2,
             t("The maximum number of posts to display in the block.")); 
	return $output;
}
rosshj’s picture

what do I do next? How do you adjust the settings?

-
Graphic / Web Designer
Donat Group Enterprises
Project Opus

klhowells’s picture

Changed the code in the blog module, but couldn't find the setting on any of the admin pages.

I changed the '10' on this line:

$limitnum = variable_get("blog_maxdisp", 10);

to '5' and that worked just fine.

Dubber Dan’s picture

Once you've altered the code you will then have a new setting available at administer > settings > blog where you can select the number of posts

mlaw’s picture

This works in drupal 6 blog.module. Although I couldn't find the location in the Administer section to change the setting, I just opened up a text editor and changed the value in there.

// Get the max number of posts to display
$limitnum = variable_get("blog_maxdisp", 10);

Change the value 10 to something else.

Remember to copy and paste blog.module to make a back up of it first (in case you're scared of messing something up).

lashari’s picture

Its very easy to change recent post in blog block from 10 to 5.
There is db queury range code line in function blog_block function. Which is available in blog.module file. Just you need to change 10 to 5 value in the following line of function.
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10);
This is working fine for me.
Enjoy!

bassplaya’s picture

what about recent comments for nodes, instead of using the blog module?
I'm struggling to set all the requirements for that? Should it be done better with views?

Authentically,
BassPlaya

voqk’s picture

worked perfectly. Thanks

markconroy’s picture

Thanks for this option. I just went to my file manager, scrolled down to the end of the page, changed "10" to "5" and hey presto, it works. Simple.

Good luck to the rest of you.

Mark
www.markconroy.net/blog

============

Drupal Core Maintainer for "Out of the Box" Initiative.

wwwoliondorcom’s picture

Thanks a lot, and does it work with Drupal 6 ?

darthux’s picture

As mentioned above, i just changed the 10 to 5 in Drupal 6.
1. create a copy of your blog.module file.
2. opened modules/blog/blog.module in text editor.
line 203 has following code:

$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10);

3. i changed the end (as mentioned above) to:

$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 5);
jchild’s picture

here is the code i changed to make the comment block only display 5 instead of ten

edit the comment.module and look for the following

 * Find a number of recent comments. This is done in two steps.
 *   1. Find the n (specified by $number) nodes that have the most recent
 *      comments.  This is done by querying node_comment_statistics which has
 *      an index on last_comment_timestamp, and is thus a fast query.
 *   2. Loading the information from the comments table based on the nids found
 *      in step 1.
 *
 * @param $number (optional) The maximum number of comments to find.
 * @return $comments An array of comment objects each containing a nid,
 *   subject, cid, and timstamp, or an empty array if there are no recent
 *   comments visible to the current user.
 */
function comment_get_recent($number = 10) {

and change 10 to 5 or whatever number you want

bassplaya’s picture

Hey, this works!! Thanx a lot.
I forgot that I created a view for this block too.. it confused me initially :-))

Do you happen to know how to set the amount of characters showing up in those links in the block?

Authentically,
BassPlaya

Biggynuff’s picture

Hi all,

I've changed the line

function comment_get_recent($number = 10) {

in comment.module to 5, but I'm still seeing up to 10 comments on the page in my block. Any suggestions? Are there any patches to work with D5.7?

Not a major oncern, but would be nice to be able to change this?

btw I'm only bothered about recent comments, not blogs etc

Thanks

Biggy

zoia’s picture

another one that spend a night in the administration page-:) thanks for the solution

bdawg8569’s picture

I created a small module to enhance the recent comments block. You can find the details at

http://bri-space.com/content/enhanced-recent-comments-module

Brian

m13’s picture

you can simply use views and display anything you like.

view type: node

Filters:
node published: yes
node type: blog entry

short criteria
post date: desc

fields:
(whatever you like)
node title: (link this field to its node)
user: picture (suppose we want to also display the picture of the user who posted a blog entry)

basic settings:
items to display: 10 (or 100 or 0 for unlimited)

add block display

save and you are done.

I don't get it. Why make it a "future request" for the blog module and not use views to achieve what you want. No need to write any code, plus you can choose any fields you wish the block to display.

hope this helped

MarieHuynh’s picture

Are you talking about content management/content types? I'm not seeing the things you're talking about. What version are you using?

marcoBauli’s picture

I reckon the possibility of adjusting the number of recent blog posts should be available out-of-the-box, without installing other extra modules. Also Views is not one of the simplest ones out there. Just my 2 cents.

Morfeusz’s picture

Or if you have to dig into the code to do it, it should be described in the handbook. I wish we had documentation as good as WordPress.

patrickharris’s picture

above comment is copied from earlier in the page

pvpaneque’s picture

friends thanks a lot, this works perfectly ,better imposible !!!!

Garry Egan’s picture

After there is a new Drupal core release...."Hmm, what was the search term for that page again?" "Um, limit comments block drupal? No, show number of posts drupal?" "limit showing number of posts drupal block?"