How to create a custom module in Drupal 7 and using hook_menu

preview_player
Показать описание
In this video we create a custom module, learning about the .info and .module files. We create a simple page that outputs a list of content.
Рекомендации по теме
Комментарии
Автор

Thank you. It helped me create custom module.

DreamediaDarwin
Автор

so total newb here... In Drupal 7.53 using PHP 5.6.24 I did get Hello World to show up, but after that, when I put the other blocks of code I get this error:

Notice: Undefined variable: news_items in my_news_list() (line 30 of
Warning: Invalid argument supplied for foreach() in my_news_list() (line 30 of

Maybe I'm missing something... Any thoughts?

olliebutler
Автор

In Drupal 7.53 using PHP 5.6.24 I did get Hello World to show up, but
after that, when I put the other blocks of code I get this error:
Notice: Undefined variable: news_items in my_news_list() (line 27 of Invalid argument supplied for foreach() in my_news_list() (line 27 of


code is lik this:<?php

function my_news_menu() {
$items = array();
$items['mynews'] = array(
'page callback' => 'my_news_list',
'access arguments' => array('access content'),
);
return $items;
}

function my_news_list(){

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'news')
->propertyCondition('status', NODE_PUBLISHED)
->propertyOrderBy('Created', 'DESC')
->range (0, 2);
$return = $query->execute();

if (isset($result['node'])) {
$news_items_nids = array_keys($result['node']);
$news_items = entity_load('node', $news_items_nids);
}
$output = "<ul>\n";
foreach($news_items as $news_item) {
$snippet = "<li>/n";
$snippet
$snippet .="<p>".t(substr($news_item->body['und'][0]['value'], 0, 600))."</p>\n";
$snippet .= "<li>/n";

$output .=$snippet;
}
$output .= "<ul>\n";

return $output;
}

Maybe I'm missing something... Any thoughts?

Please let me know.

navyashree
Автор

The sound of you writing on the keyboard is so annoying I can barely hear anything..

shphrdOfFire
visit shbcf.ru