How display article from category and show it in block - drupal-7

I have created a content type which has some fields, and I want these fields to be displayed as a block.
I need to display some article like 5 articles from category called sport news only.
How can I do that in drupal 7?

You need to install Views
https://drupal.org/node/1960048
Then create a new view as a block.

Related

Drupal 7 - assign several products (items) under each category

In D7, I have created a taxonomy (say categories) and set some terms (say category 1, category 2 etc) within it. I have also created a 'View' based on the 'categories' taxonomy and show the categories (category 1, category 2 etc) within the sidebar (block) of the website. Just let me know how can I assign several products (items) under each category so that site visitors can see the product lists on clicking a category from the sidebar. Basically I want to develop a catalogue based website to show products/items under each category.
Kindly help me in this regard.
Good morning,
If you have not done yet, you have to create a custom content type (Structure > Content Types > Add content type) and add as many fields as you need. When you are done, you have to add an extra field named Category, of type "Taxonomy Term Reference" (or something similar, I don't know exactly). You can configure this field so that you can assign several categories to a single product.
Once your contents are created, if you access the taxonomy term's URL, all contents assigned to that category should be displayed. However, you could also define a custom view that receives the name of the category as a parameter in the URL, and displays all contents in this category in a grid, table, list, ... whatever.
Hope it helps.

In Drupal 7 views how to give external link (another website) to a title?

Iam new to drupal 7 views.
I have a content type contains title, description fields. I want the content title's to scroll at the top of the page, so that i created a view and it works fine.What is my question is, i want to link a content (eg: 1st content (title) in a scroll) to another website instead of content page, the remaining contents linked to the content page. Is it possible?.If it is possible how it can be done?..
Thanks in advance,
A.John Melchior.
Yes, it's possible.
One way to do it, would be to use the Link module to create a link field in your node.
Use the link field to input the external link value.
In views add the link field, before the title ( order is important ) and exclude it from display
Add the node title field in the views and in the rewrite field output option, use one the link field token as your path.
I'm not looking at the Views UI right now , but you should find at least a couple of ways to redirect content when the node title is clicked. You should have the Rewrite field output and the Output this field as a link.
You could make use of Display Suite coupled with the description above.
Create a link field for your nodes.
Create 2 view modes for your content type via Display Suite. View Mode 1 will show the link field as the first data element, View Mode 2 will show the title as the first element.
Configure your view to show output using Display Suite, configured to show the first record using View Mode 1, all others using View Mode 2.

Drupal 7: Adding content/nodes from custom content type pages to another page

I'm working on a Drupal site an need to implement the following:
I have created an about us page template (page--about.tpl.php) and a custom content type for the about us page and linked the 2 using suggestions. I also have a custom content type for staff profiles that I need to add on the about us page in a tabbed format.
I can't seem to find a way to get the staff content to display in the about us page. I would ideally like it to render it the same manner as blog posts would display in a blog page.
So my question is, what code do I use to render all the nodes of the staff profiles content type in the about template page?
p.s I'm a bit of a Drupal noob, done a lot of reading but come up empty on this one.
If you already created content type About us (that is what i understood from mockup and explanation) then maybe you could use Views with EVA. That will enable you to have view as field in content type.
You can set it up with manage display or print it in template as all other fields. For example:
<?php print render($content['your_view_entity_view_1']); ?>
Other way would be to embed view in template. For example:
<?php print views_embed_view('your_view', 'block'); ?>
You can use the excellent Views module to create a block to list all your staffs.
Then you need to place the block that you had created with the help of view module in about-us page.
The Views module will give you suggestions to about which template to use.
EDIT: After the op provided the following image.
After you create a view to show all the Team member nodes you could simply print the view in your about us specific page template using following code.
$view = views_get_view('view name');
print $view->render('display_id');
Another option to do the same thing is, make blocks for all the content, viz. The Firm, The Team, Awards, Technonogly, Services and use quicktabs to display the content.
Yet another option to show a view as a field for a node is use EVA
Going the quicktabs way you can provide a lot of flexibility of showing teaser in about us page and leading to details about the same. For example each award can be a node in itself.

layout for article by css and get fields with php

I would insert some custom article in drupal. That every article,
some fields that I decided.
Then I would like these article are displayed with a graphic set from CSS.
So I would take for each article, the fields with php.
How do I post article with the graphics set to css? and how to take php variables?
Thank you.
From your answer to my comment it sounds like you would like to edit the article content type and then "theme" the resulting page.
You can add fields to any content type (or add new content types) in "Content Types" in the admin. Select the type you want (article) and click "Manage fields". Here you can add as many fields or whatever type as you like. Each field will be given a machine name, widget and there will be a wizard to follow that explains all the relevant options.
Once all your fields are added, click "Manage Display" to change the order and way the fields are displayed.
To add a template to your theme, create a folder in your themes folder called "templates". Then copy node.tpl.php from root/modules/node/ to this new folder. Rename the copied file to node--machine_name.tpl.php. So for the content type "article" you would change the file to node--article.tpl.php.
Clear your cache (admin/config/development/performance) and that content type will be using that new template. By default all fields will be displayed by this line of code print render($content); If you comment that line out you can display fields individually but taking the fields machine name and doing <?php print render($content['field_page_image']); ?>
Read up on Drupal theming, there are a lot of good docs out there.

How do you display info from a database

I have figured out how to add data from a model into a grid like the examples on the learning section of the Agile Toolkit website. But I'm looking for the correct way to show data from a database without a grid.
Say I have a news database and I want to display it as a blog style news on my home page. Can someone point me to where to begin?
Trying to make this a little more clear:
I want to display data from multiple columns from a table news. So I would need to know how to get the title, date, author, content and then repeat that for say 5 latest news articles.
try this:
$this->add('View',null,null,array('view/mytemplate'))
->setModel('MyModel')
->loadData(123);
then inside templates/defaults/view/mytemplate.html
<div><h2><?$title?></h2>
<p><?$content?></p>
</div>
You can also use it with any view, even page.
$data=$model->get();
$page->template->set($data);
you can re-define template for your page by defining defaultTemplate function
function defaultTemplate(){
return array('page/mypage');
}

Resources