Search code examples
phpdrupal-7

Override callback function in Drupal7


I am using blog module. I can access it using this URL: http://localhost/drupal/blog. I have put some posts.

In the blog content type, I have added a field such as posted date. When I open the same URL http://localhost/drupal/blog, blog posts are coming using ordering on submitted date.

Now I want that posts should be list out using order by newly added field "posted_date". I don't want to change default functionality defined in the blog.pages.inc page. please suggest!


Solution

  • Create this function in module_name.module file in the custom module.

    Ex: sites/all/modules/custom/module_name/moduleName.module

    /**
     * Implements hook_menu().
     */
    function moduleName_menu() {
    $items['blog'] = array(
        'title' => 'Blogs',
        'page callback' => 'blog_list',
        'access callback' => TRUE,
        'file' => 'page_name.inc',
        'type' => MENU_CALLBACK  
      );
    }
    

    Create a file moduleName.pages.inc and define callback function.

    Exm: sites/all/modules/custom/moduleName/moduleName.pages.inc

    function blog_list() {
       return t('welcome blog');
    }
    

    I hope it will work for you cheers!