drupal-4.6.4
http://www.shreemaa.org

I would like to limit the number of posts on the front page to 3 with a time limit of 2 days.
I don't see a setting for this in my drupal dist.

can anyone help?

thanks.
Susan

Comments

sjames’s picture

change the number of posts on the front page at content|configure.

klcthebookworm’s picture

I have changed the number of posts on the first page and then it just adds more pages with links at the bottom so you can scroll through and see when everything was loaded in.

Not what I want. 5 latest entries on the front page and go to the index page to find the rest is what I want. How do you get ride of those links?

klcthebookworm’s picture

Nobody knows how to get rid of the links? The theme I'm hacking is bluemarine.

sepeck’s picture

You would want to uncheck the promite to front page box manually to prevent the pager list on the bottom. You could also look in to scheudler module, I believe it can promote/demote pages on a user determined schedule. Not entirely sure though.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

klcthebookworm’s picture

Thanks. I'll look into the scheduler module. I want stuff to be on the front page so users will see the new stuff, but not to have it there forever. And having it done automatically would be a big plus.

sjames’s picture

Let us know what you find.
i.e. if the scheduler module works.

thanks!

klcthebookworm’s picture

On the surface, the Schedule module looked like it was going to work. But how it takes items off the front page is by unpublishing them. I've put in a feature request to add an option to take away "promote to the front page" but not to unpublish, but I don't know how long that's going to take.

I looked at Cron jobs, and while I think I understand it well-enough to set one up, there doesn't seem to be a list of commands that are okay to use. Anybody have any ideas how to make a cron job to unpromote items that are over a week old? Is it even possible to do?

At this point, if the cron job idea is just a pipe dream, I think I'm going to have to use PHP snippets to create a new version of the page and keep the automatic promote-to-the-front-page off.

Sascha Mantscheff’s picture

A naive first glance reveals a field "promote" in the node table. Try this: Let your cronjob set the node items which are not wanted on the front page to "0", depending on the value of the "created" or "changed" field.

klcthebookworm’s picture

My friend Billy came up with the script, and SiteGround and Drupal members helped come up with the rest of these instructions.

  1. Create a new php page with the below code. Change mysql_user, mysql_password, and mysql_database to your Drupal code.
    <?php 
    // we connect to localhost 
    $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); 
    if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
    } 
    $db_selected = mysql_select_db('mysql_database', $link); 
    $query = "UPDATE node SET promote = 0 WHERE UNIX_TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL 7 DAY)) > created"; 
    $result = mysql_query($query); 
    f (!$result) { 
    $message = 'Invalid query: ' . mysql_error() . "\n"; 
    $message .= 'Whole query: ' . $query; 
    die($message); 
    } 
    ?> 
    


  2. Save this file in your main directory.

  3. Create a CRON job to run that file. If you have cpanel, they should have a section labeled "CRON jobs." Under Standard settings, you need to put something like this for the command line: /usr/local/bin/php -f home/account_name/public_html/new_cron_file.php
    Replace what you need to to apply it for your Drupal site.

  4. You can set how often you want it to run with the time settings, and save.

  5. You can run it without waiting by just going to the new_cron_file.php

Hope this helps someone else.

heine’s picture

To make a module that implements hook_cron and runs this query.
--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.

klcthebookworm’s picture

I'm sure it is, but I don't know how to make a module.

Anyways, it's messy but it works. Hopefully, they make the changes to the Scheduler module and we'll be able to just use that.

heine’s picture

Create the file mylittlemodule.module (in modules/mylittlemodule)

Contents:


function mylittlemodule_cron() {
  // Query supports prefixed tables.
  $query = "UPDATE {node} n SET n.promote = 0 WHERE UNIX_TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL 7 DAY)) > n.created";
  db_query($query);  
}

(omit the last ?> from the file). To beautify, also implement hook_help.
--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.

sjames’s picture

drupal-4.6.4
http://www.shreemaa.org

is this the code to use:

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

function mylittlemodule_cron() {
  // Query supports prefixed tables.
  $query = "UPDATE {node} n SET n.promote = 0 WHERE UNIX_TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL 7 DAY)) > n.created";
  db_query($query); 
}
=============

what do you mean when you say:  (omit the last 

from the file).?
is this just a module rather than a cronjob?

thanks.
Susan

amnon’s picture

I would like to limit the number of posts on the front page to 3 with a time limit of 2 days.

I want stuff to be on the front page so users will see the new stuff, but not to have it there forever.

This can easily be done with the 'views' module.

  1. check 'Provide Page View', uncheck 'Use Pager', enter '3' in 'Nodes Per Page'.
  2. in 'Filters', add 'Node: Front Page' (or 'Node: Promoted', whatever you prefer).
  3. in 'Filters', add 'Node: Created Time'.
  4. in the conditions, choose 'Is Greater Than', 'now', '-172800' (this is the number of seconds in two days).
  5. in 'Sort Criteria', add 'Node: Created Time', 'Descending'.
  6. The final touch: add a link in the 'Footer' to the original front page, e.g.: {a href="q=/node"}See the full list of stories{/a}
  7. Make this view your new front page

(I hope I haven't forgotten anything.)

change the number of posts on the front page at content|configure

No, that's not a good idea, because this setting governs lots of other lists too.

sjames’s picture

drupal-4.6.4
I installed the views module and enabled it in modules.
I also added the tables to the database.

but, where do I do this stuff:
# check 'Provide Page View', uncheck 'Use Pager', enter '3' in 'Nodes Per Page'.
# in 'Filters', add 'Node: Front Page' (or 'Node: Promoted', whatever you prefer).
# in 'Filters', add 'Node: Created Time'.
etc.

I don't have a 'views' in settings.
where is the above done?

thanks for your help!
Susan

sjames’s picture

drupal-4.6.4

ok. I couldn't see Views because I didn't allow access.
now, I can see it and the config page.
but, it's different than your steps.

below is what I see on my 'Views' config page.
all I want to do is limit the number of pages on the home page pager to 1.
I don't see a way to do that with this module. can anyone clarify?

thanks!
Susan

==================================
Add a View
Display
Name:*
The name of the view. The URL of the view will be views/NAME. If a block, this will be the unique identifier for the block. Since this is a URL, please do not use spaces!
Description:
A description of the view for the admin list.
View Type:
How the nodes should be displayed to the user.
Title:
The title of the view will be shown at the top of the view. May be blank if not using a block.
Header:
Text to display at the top of the view. May contain an explanation or links or whatever you like. Optional.
Input format:

Filtered HTML

    * Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
    * Lines and paragraphs break automatically.
    * You may post PHP code. You should include <?php ?> tags.
    * You may link to webpages through the weblinks registry

PHP code

    * You may post PHP code. You should include <?php ?> tags.

Full HTML

    * Lines and paragraphs break automatically.
    * You may link to webpages through the weblinks registry

More information about formatting options
Table

Fields in this section will appear in the table in this order, only if List Type above is set to Table.
Add a Field:
Block
Provide Block
If checked this view will be provided as a block. If checked title may not be blank.
Nodes per Block:*
If using a block, the maximum number of items to display in the block. Pagers are not used in blocks.
Display Header
If using a view as both a block and URL, display the header in the block?
URL
URL Type:
Choose whether or not to provide a URL and a Menu entry for this view..
Pager
Use Pager
If checked this query may be multiple pages. If not checked this query will be one page.
Nodes per Page:*
The number of nodes to display per page. If 0 no nodes will be displayed. If not using a pager, this will be the maximum number of nodes in the list.
Current Arguments

This view does not accept arguments
Add an Argument
Argument:
If using a URL and you want it to accept arguments, this is how to parse the argument. For example, "views/VIEWNAME/1" could produce nodes authored by User ID #1 if this field is set to User ID. It can accept multiple, successive arguments..
Argument Default:
If argument 1 was specified, what action to take if the argument is not given.
Filters

No filtering Criteria Specified
Add Filter
Filter:
Use this box to add a new Filter
Sorting Criteria
The order of criteria from top to bottom determines which fields will be sorted first.
Add Sorting Criteria
Criteria:
Order:
Use this box to add a new sort criteria
==================================================

klcthebookworm’s picture

Now that I've gone live, the CRON job solution isn't working. *Sigh*

I'm looking at the views solution, since I had to add it for something else. I have a Front Page view listed that has most of the list already created on it, but I can't find this one:

4. in the conditions, choose 'Is Greater Than', 'now', '-172800' (this is the number of seconds in two days).

I'm using drupal 4.7.2 and the filters doesn't seem to have a place to put in conditions.

EDIT: Never mind. Played with it some more and got it working.