I tried to create a block
called contact details
. I already created a content type
called contact
. I wanted to add the content of each contact content type in my custom block. I researched a lo abd I'm confused.
In block_view
of your custom block write this code
$nids = db_select('node', 'n')
->fields('n', array('nid'))
->fields('n', array('type'))
->condition('n.type', 'contact')
->execute()
->fetchCol();
$nodes = node_load_multiple($nids);
Loop $nodes
with foreach
and get the fields whatever you want.
- Install and enable the Views module.
- Create a view with 'Block' display.
- Filter by content type 'contact'. You can also choose sort options, etc.
- Go to the Blocks administration page at Administration > Structure > Blocks.
- Enable the Views block.
So you can do some custom work to the output of those fields? I hope that's right.
So this is relatively easy depending in how you want to go about this.
Follow steps:
You've created your content type and added all of the fields that you want. I'm assuming you've also created some content already to test the next part.
You need to create a view that has a block display. See screenshot for an example. https://skitch.com/therealwebguy/8ksue/block-step-1
Set up your block view appropriately. See screenshot for more specific details for this: https://skitch.com/therealwebguy/8ksw9/block-step-2
If you refer to the screenshot provided in Step 3, you'll notice in the bottom right that I have highlighted the "Information" link for the Theme layer. Clicking this link will bring up a list of all of the .tpl files you can create for this view to target what you need. It has everything from the top-level view tpl to the output of a single field being rendered by the view. Choose the one that's best for you needs, copy the HTML provided and add it the view.tpl.php file you've chosen to use.
Lets recap:
- We've create a content type and added fields to it.
- We've added actual nodes of the new content type for testing.
- We've created a new view which will provide a block display, showing us > the field values of our content type that we want to show.
- We've created a custom tpl override for the view of our choice to do some more customization at the theme level that best fits our needs.
The only thing left to do is to head over to your blocks administration and put the block where you want it.
Hope this help to solve your problem/doubt.
-
Nice tutorial, but this isn't a tutorial site. #3 in your recap is really the only step relevant to the question, and that's already been covered. – othermachines Aug 14 '15 at 14:08
Your need to use core contact form and uses contact save to save and fetch contact detail. thats it.