开发者

How can I show a certain type of contents on a specified page with Drupal 7

When I create a content type, I want to show all the posts of this content type on a page, I have to use view module. I don't like that.

Can I just specify the page and url when I create the content type?

But there is only one option, only front page. Can I cha开发者_StackOverflownge that? Hope you guys can tell me.


The views module is one of Drupal's killer features, you might want to reconsider writing it off completely.

Anyways, if you want to display all nodes of a type, you will have to code this yourself in a custom module. This means you will have to write some SQL, load the nodes and render them in a list. In this example you could use the EntityFieldQuery class to construct the query instead of writing the SQL yourself.

The end result will not be much different than what views will do for you, only difference is that you will need to create all of this with code in a module, instead of just setting this up in the Views UI.


I agree that views is a powerful tool that you shouldn't count out, but if you're set against using it (i refuse to use it on 2 of my sites purely due to overhead), You could use taxonomy instead. The taxonomy module already has a views style list for each term, I used this to achieve something similar to what you're looking for:

Set up a vocabulary whose terms match your node types and note the vid

add a hook_node_insert into your module file:

mymodulename_node_insert($node){
  $terms=taxonomy_get_tree($my_vid); //where $my_vid == the vid of your vocabulary.
  foreach($terms as $term){
   if(strtolower($node->type)==strtolower($term->name)){
      $items=array((array)$term);
      $field['storage']['type']='field_sql_storage';
      taxonomy_field_insert('node', $node, $field, null, null, $items);
    }
  }
}

After that you just need to add menu links pointing to your taxonomy page. Just as a note, I render all of my lists that I don't use views for with my own custom functions so I'm not sure what limitations this method might present.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜