0

After months of figuring out how to upload a background image, I decided to scrap that and use a solid color with the color picker.

Now I moving on making a custom theme and it's very different from making a WordPress theme. So I need help with the following:

On my page.tpl.php, is there a way to have the first post different from the rest of the posts? Example: First post has a title, date, time and a description. The rest just have a date and title.

Also I don't want to use view module as it looks complicated to setup and I want to use as little of modules as possible.

All help is greatly appreciated and thanks for understanding my annoying questions for help, Gregory S.

UPDATE: Looks like I'll have to do views after all.

  • content type maybe? – GwenM Jun 13 '15 at 8:56
  • a proper answer requires knowing how you are displaying the content? – Geoff Jun 13 '15 at 15:33
1

Using views module to make it :

  1. go to -> views -> add new view
  2. give a name
  3. Check Create a page , give a title and a path for the page
  4. leave other settings for now and press Save and Continue
  5. now in Page Settings -> Use Pager -> click on Paged,...
  6. change offset to '1' (this will skip the first node)
  7. in top menu there is a ADD menu just beside PAGE menu , Click ADD
  8. Select 'ATTACHMENT'
  9. In format Pane Change Display format to HTML LIST (choose for option as "THIS PAGE")
  10. Change Show to Fileds (choose for option as "THIS PAGE")
  11. List Field Items you want to display (Again don't forget to change "For" Settings or you would alter other display)
  12. ATTACHMENT SETTINGS -> attach to -> page
  13. ATTACHMENT SETTINGS -> ITEMS TO DISPLAY -> '1'

now you have done some thing . to have a better format for display its better to learn "Pannels" And "Page Manager" Modules too .

| improve this answer | |
  • Is there a way to add an attachment to the page.tpl.php? This is for styling purposes. – Gregory Schultz Jun 19 '15 at 7:01
  • Maybe there is a way but you can create a block rather than a attachment then view it on your page using blocks . its more regular. – Alireza Tabatabaeian Jun 19 '15 at 11:01
1

What you can do is:

  1. Create a custom page using hook_menu.
  2. Use Drupal's Database (DBTNG) to get your list of contents. You can do two separate queries for this. The first one would just return one result with more fields than the second. Also you could add the Drupal's pager functionality right out of the box here since you will be using db_select.
  3. Use hook_theme to create the template for your "node teaser" so that it makes your raw data manipulation separate from your presentation hence the need for a custom template.

Your main code would somewhat look like:

function YOURMODULE_page_view() {
  $special_node = db_select(...);
  $nodes = db_select(...);
  $output = array();

  // do stuff here for $special_node_fields
  $output[] = theme('custom_node_theme', $special_node_fields);

  // look through all remaining nodes
  while($nodes) {
    // do stuff here for $node_fields
    $output[] = theme('custom_node_theme', $node_fields);
  }

  return $output;
}

This gives you better view on the data manipulation you need to get the list you need.

Also don't forget to replace the Default front page value with your custom page in the Site Configuration page.

| improve this answer | |
  • Querying a database will slow down the website? – Gregory Schultz Jun 13 '15 at 21:41
  • Everything is done by querying but drupal also comes with a caching module so you can cache your queries. Modules just make your development better. :) – Leolando Tan Jun 13 '15 at 21:58
1

The easiest solution is by using views module , it will take you just a few minutes but if you really want to ignore it , there would be another way :

Download and install the devel module (you will find it as a helping hand when developing on drupal , when you are done developing you can unistall it)

in your theme folder you would need a page-front.tpl.php , drupal will use this file (if exist) to make front page of the site . for now just copy and rename the page.tpl.php to make this file .

in page-front.tpl.php file enter this code in the first line:

dsm($content);

now visit your home page , there should be a box containing details about content variable of your home page . take some times and you will find many variables which you can build your frontpage with .

Note: The Views module has an option called Display format , if you want to deal with fields (like title , body or even author and .. ) you must select a field view type (like HTML List of Fields) then in fields tab you can add and arrange fields . One more thing if you want to have a view that has two different kind of display (example : first node in full body and rest of the nodes in trimmed format) use Views Attachment for the job.

| improve this answer | |
  • How do I pass the title of the node to the view? I have a view set up to display the first post that is in the content type called ctrl_daily. I can see it as a row and need more customization. – Gregory Schultz Jun 15 '15 at 6:38
  • Views module has an option called Display format , if you want to deal with fields (like title , body or even author and .. ) you must select a field view type (like HTML List of Fields) then in fields tab you can add and arrange fields . One more thing if you want to have a view that has two different kind of display (example : first node in full body and rest of the nodes in trimmed format) use Views Attachment for the job. – Alireza Tabatabaeian Jun 15 '15 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.