Build a blog archive block with code
create a new folder in /sites/default/modules 
create a custom_blocks.info file inside that folder 
add this content in the file:



name = Custom blocks
description = "A short description of your module"
package = My modules
files[] = custom_blocks.module
core = 7.x



create another file: custom_blocks.module (note that you've specified this in the info file)
add this PHP code:




&lt;?php
  function custom_blocks_block_info() {
    $blocks = array();

    $blocks['unique_id_for_your_block'] = array(
      'info' =&gt; t('block info'),
      'cache' =&gt; DRUPAL_NO_CACHE,
    );

    // You can add more blocks here.

    return $blocks;
  }

  function custom_blocks_block_view($delta = '') {
    $block = array();

    switch ($delta) {
      case 'unique_id_for_your_block':

        // Put your logic here and generate the HTML you want to display in your block.
        $block['subject'] = t('block title');
        $block['content'] = 'Put here the HTML generated above';
        break;

      // Add more case statements here if you defined more than one block.

    }

    return $block;
  }



go to your module page, activate the module, go to the block configuration page and activate your new block
read more here: 

Writing a Drupal 7 module
Drupal 7 Block API