I've looked high and low and I cannot seem to find out the correct way to render/print a content type and its content to a custom front page via PHP. Unfortunately, I don't think Views would help me in this scenario, but if I'm wrong, please tell me.

My current scenario is this:

I have three HTML sections on the page--front.tpl.php that I would like render a certain content type in each of those sections. For two of the content types I would like to print out all of the pieces of content in that content type (sorted by latest authored), while the third content type I want only the latest 3 that were authored (not updated).

Is this possible at all? I'm trying to find out the correct code to even see what can be passed to the front page and my googlefu has failed me.

Thanks in advance, this is been a bugger for me.

Comments

nevets’s picture

My first thought would be to use the views and panels modules.

Views to make the 3 lists.

Panels to make a page (that will be you front page) and add each of the 3 views as content.

rooooooot’s picture

Would views/panels assist me if I need the three most recently added pieces of content? I'm also trying to place this into some custom HTML and render it differently then else where on the site. I figured custom PHP would be the best to access the database and grab the stuff I need, but I just have no idea where to begin. Thank you for your response.

nevets’s picture

Views can be used to list the three most recently added pieces of content. Panels is for creating pages with multiple pieces of content that go beyond a list.

How do you want to customize the html? To what purpose?

dhirendragrazitti’s picture

Yes it is possible via PHP.
Lets suppose that You had create content type event and you want to render event content type on certain section.
(1) Create a custom functions in PHP.
(2) Get Required field of Content Type Event. suppose I want to display Event title, Event date, Event Place, Event Image
(3) Using foreach and endforeach you can display results.


function EventImageListing()
{
	$query = db_select('node', 'n');
	$query->fields('n', array('nid','type','title','status','created'));
	$query->fields('fm', array('filename'));
	$query->fields('ed', array('field_event_date_value'));
	$query->fields('fdfep', array('field_event_place_value'));
	$query->leftjoin('field_data_field_event_date','ed','n.nid=ed.entity_id');
	$query->leftjoin('field_data_field_event_image','fdfui','n.nid=fdfui.entity_id');
	$query->leftjoin('field_data_field_event_place','fdfep','n.nid=fdfep.entity_id');
	$query->leftjoin('file_managed','fm','fdfui.field_event_image_fid=fm.fid');
	$query->condition('n.type','event','=');
	$query->range(0,3);
    $results = $query->execute();					
	$countryBox = array();
	while($record = $results->fetchAssoc()): 
      	 array_push($countryBox,$record);
	endwhile;   
	return $countryBox;
}

Now function will return 3 latest records in array format.

Array
(
[0] => Array
(
[nid] => 8
[type] => event
[title] => Event Name
[status] => 1
[created] => 1390224704
[filename] => Event3.png
[field_event_date_value] => 2014-01-20 13:30:00
[field_event_place_value] => CA (AU)
)

[1] => Array
(
[nid] => 9
[type] => event
[title] => Event2
[status] => 1
[created] => 1390224786
[filename] => Event2.png
[field_event_date_value] => 2014-01-20 13:30:00
[field_event_place_value] => UK
)

[2] => Array
(
[nid] => 10
[type] => event
[title] => Event Name 4
[status] => 1
[created] => 1390224922
[filename] => Event1.png
[field_event_date_value] => 2014-01-20 13:30:00
[field_event_place_value] => Ca (UK)
)

)

now on by using foreach you can display required results on page--front.tpl.php.


if(sizeof($eventdata) > 0):
            foreach($eventdata as $eventval):
          
                print  $eventval['filename'];
                print text_cut($eventval['title'],'18');
                print date("jS F, Y", strtotime($eventval['field_event_date_value']));
                print text_cut($eventval['field_event_place_value'],'10');
	   endforeach;
	  endif;