By Seraph-1 on
I'm not fluent with PHP, what would I edit in this PHP file to have it display just a list of node cotent and not the letters? Output is this:
* f
* g
f
* First Date Tips. Things To Do On First Date.
g
* Getting Ones Phone Number Aint That Hard
I just want:
* First Date Tips. Things To Do On First Date.
* Getting Ones Phone Number Aint That Hard
It's the node list module. Any help is very much appreciated!
/**
* File: nodelist.module
* Version: $Id: nodelist.module,v 1.3.2.4 2005/05/02 16:12:48 njivy Exp $
* Author: Nic Ivy (nji@njivy.org)
* Description:
*
* This module provides a page listing nodes by their titles, linking to
* the nodes directly. The list is sorted alphabetically.
*/
/**
* Implementation of hook_help()
*/
function nodelist_help($section = 'admin/help#nodelist') {
switch ($section) {
case 'admin/modules#description':
return t('List all nodes by title');
}
}
/**
* Implementation of hook_menu()
*/
function nodelist_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('title' => t('node list'),
'access' => user_access('access content'),
'path' => 'node/list',
'callback' => 'nodelist_page',
'type' => MENU_SUGGESTED_ITEM);
}
else {
if (arg(0) == 'vocabulary' && arg(1) && arg(2) == 'list') {
$items[] = array('title' => t('node list'),
'access' => user_access('access content'),
'path' => 'vocabulary/' . arg(1) . '/list',
'callback' => 'nodelist_page',
'callback arguments' => array('vocab', arg(1)),
'type' => MENU_CALLBACK);
}
else if (arg(0) == 'taxonomy' && arg(1) == 'term' && arg(2) && arg(3) == 'list') {
$items[] = array('title' => t('node list'),
'access' => user_access('access content'),
'path' => 'taxonomy/term/' . arg(2) . '/list',
'callback' => 'nodelist_page',
'callback arguments' => array('term', arg(2)),
'type' => MENU_CALLBACK);
}
}
return $items;
}
/**
* Implementation of hook_nodeapi()
*/
function nodelist_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'delete':
case 'insert':
case 'update':
cache_clear_all('nodelist:', TRUE);
}
}
/**
* Implementation of hook_page();
*/
function nodelist_page($type = NULL, $id = NULL) {
//
// Determine the appropriate page title
//
switch ($type) {
case 'vocab':
$title = db_fetch_object(db_query('SELECT name FROM {vocabulary} WHERE vid = %d', $id));
drupal_set_title(t(variable_get('nodelist_vocab_page_title', t('node list: %id')), array('%id' => $title->name)));
break;
case 'term':
$title = db_fetch_object(db_query('SELECT name FROM {term_data} WHERE tid = %d', $id));
drupal_set_title(t(variable_get('nodelist_term_page_title', t('node list: %id')), array('%id' => $title->name)));
break;
default:
drupal_set_title(variable_get('nodelist_page_title', t('node list')));
}
print theme('page', nodelist_render($type, $id));
}
/**
* Render the node list. This function can be called
* from any page or block.
*
* @param $type Either 'vocab', 'term', or NULL
* @param $id The identifier for the type -- i.e. the vid, tid, or NULL
* @return An HTML-formatted string ready for printing to the screen
*/
function nodelist_render($type = NULL, $id = NULL) {
$node_types = variable_get('nodelist_types', array());
if (!count($node_types)) {
drupal_set_message(t('Please select which node types to list.'), 'error');
drupal_goto('admin/settings/nodelist');
}
switch ($type) {
case 'vocab':
$type_join_sql = ' LEFT JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {term_data} td ON td.tid = tn.tid';
$type_where_sql = ' AND td.vid = "' . db_escape_string($id) . '"';
break;
case 'term':
$type_join_sql = ' LEFT JOIN {term_node} tn ON n.nid = tn.nid';
$type_where_sql = ' AND tn.tid = "' . db_escape_string($id) . '"';
break;
}
$sql = 'SELECT n.nid, n.title, n.created FROM {node} n
' . $type_join_sql . '
WHERE n.status=1 AND n.moderate=0 AND n.type IN ("' . implode('", "', $node_types) . '")
' . $type_where_sql . '
ORDER BY n.title';
$sql = db_rewrite_sql($sql);
$md5 = md5($sql);
//
// Different users have different permissions, and this affects the result of this function.
// To speed things up (at the expense of some database storage), we cache the result of
// this function with the md5 of the sql as the key. Theoretically, many users will
// share the same permissions, thus the sql will be the same for many people.
//
if ($cached = cache_get('nodelist:'.$md5)) {
$output = $cached->data;
}
else {
$result = db_query($sql);
//
// Organize the nodes
//
$sorted = array();
while ($row = db_fetch_object($result)) {
$key = strtolower(preg_replace('#^.*?(\w).*#i', '$1', $row->title));
$sorted[$key][strtolower($row->title)][$row->nid] = l($row->title, 'node/' . $row->nid);
}
//
// Sort and display the nodes
//
ksort($sorted);
$list = array();
foreach (array_keys($sorted) AS $key) {
$list[] = '<a href="/' . $_SERVER['REQUEST_URI'] . "#$type-$id-$key\">$key</a> ";
}
$output .= '<div class="node-list-index">' . theme('item_list', $list) . "</div>\n";
foreach ($sorted AS $key => $group) {
ksort($group);
$list = array();
foreach ($group AS $item => $duplicates) {
ksort($duplicates);
foreach ($duplicates AS $li) {
$list[] = $li;
}
}
$output .= '<div class="node-list">' . theme('item_list', $list, "<a name=\"$type-$id-$key\"></a>$key") . "</div>\n";
}
cache_set('nodelist:'.$md5, $output);
}
return $output;
}
/**
* Implementation of hook_settings()
*/
function nodelist_settings() {
$node_types = drupal_map_assoc(node_list());
foreach ($node_types as $k => $v) {
$node_types[$k] = node_invoke($v, 'node_name');
}
$form .= form_textfield(t('Page title for all nodes'),
'nodelist_page_title',
variable_get('nodelist_page_title', t('Content list')),
32, 128);
$form .= form_textfield(t('Page title for nodes in a vocabulary'),
'nodelist_vocab_page_title',
variable_get('nodelist_vocab_page_title', t('Content list for <em>%id</em>')),
32, 128,
t('The string <em>%id</em> will be replaced with the vocabulary\'s name.'));
$form .= form_textfield(t('Page title for nodes in a taxonomy term'),
'nodelist_term_page_title',
variable_get('nodelist_term_page_title', t('Content list for <em>%id</em>')),
32, 128,
t('The string <em>%id</em> will be replaced with the term\'s name.'));
$form .= form_select(t('Node types to include'), 'nodelist_types', variable_get('nodelist_types', array()), $node_types, NULL, NULL, TRUE);
return $form;
}
Comments
What are you trying to do here?
What exactly are you trying to do here?
--R.J.
http://www.electric-escape.net/
--R.J.
Here is a start
I have commented out some lines not needed and changed a few lines. There is still gaps between the lists for each letter which can be fixed but I have run out of time.
gpdinoz
"If we can see further it is because we stand on the shoulders of giants"
Regards
Geoff
Perhaps you don't need the
Perhaps you don't need the node_list module at all.
If you only want an alphabetical list of all your nodes, then do this:
1. create a new page (or story) node
2. choose 'php' as input format
3. enter this code snippet in the body
This displays an alphabetical list of all your nodes.
Is there a way to select
Is there a way to select from a term?
Another snippet
After tenrapids excellent point that maybe you only need a php snippet I started to scout around and came up with this.
This snippet comes from the php snippets page in the drupal Handbook http://drupal.org/node/23220. I have modified it slightly. It orders the list by title alphabetically but it can be modified to order them by created date etc.
gpdinoz
"If we can see further it is because we stand on the shoulders of giants"
Regards
Geoff
Awesome! Thanks a ton!
Awesome! Thanks a ton! I'll take a look at the snipplet page. I didn't know there way one.
I don't know PHP. But to
I don't know PHP. But to change it to order from date.. Change
ORDER BY {node}.title ASC
to
ORDER BY date ASC
Nevermind, looking at the
Nevermind, looking at the other sniplets I found n.created
Any way to have this split out the date made and maybe author? This is working great though. :)
Was that a question? :-)
Actually the bit that you need to change is SQL (Yes, there is more to learn than just PHP). If you can access the database with phpMyAdmin or some other database management tool then you can look at the tables and see what their field names are and what info they hold and then all this will make more sense.
To change it to order by date created
ORDER BY created ASC ";
or
ORDER BY created DESC ";
Here are the node table headings
nid, type, title, uid, status, created, changed, comment, promote, moderate, teaser, body, revisions, sticky, format,
Regards
gpdinoz
"If we can see further it is because we stand on the shoulders of giants"
Regards
Geoff
I looked through other
I looked through other sniplets to see what the creation code was since date did not work. I ended up creating a new page that had the n.created code instead of n.title and the user clicks on that and it lists articles by date.
Would be nice to list when the article was created along side the article though, and maybe the author.