开发者

show all contents of specific content type

开发者 https://www.devze.com 2023-03-28 00:32 出处:网络
For every taxonomy term I can access a page (I am not using the Views module) showing all contents that are tagged with the specific term by using the a path like this: www.exa开发者_StackOverflow中文

For every taxonomy term I can access a page (I am not using the Views module) showing all contents that are tagged with the specific term by using the a path like this: www.exa开发者_StackOverflow中文版mple.com/taxonomy/term/1.

Now, I wonder if I could do the same with content-types (e.g. for showing all contents of content type article), using a URL such as www.example.com/content/type/1.


I'm assuming Views 3. You could create a View and supply a contextual filter in the URL to dynamically display all nodes of that content type.

Add "Content: Type" as a contextual filter. Under "When The Filter Is Not Available" section, select "Provide default value", and then Raw value from url. For your example, you would select "3" for the path component.

You can set the Path to "/content/type/%" where the % is the name of the content type. I'm not sure if it will work with numeric values, however.


Without using the Views module, you should create a custom module for doing that, which would be doing what Views is already doing. If you don't need all the features present in Views, then you can create your own module, even if I would not suggest doing it when Views already exists.

Your module should associate a menu item to a path like "content/type/%" and render a page containing all the nodes of that content type.
For rendering the nodes you could use node_view_multiple(). For retrieving the list of the nodes, and rendering it, you could use code similar to the following one:

$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', $content_type)
  ->propertyCondition('status', 1)
  ->execute();

$nodes = entity_load('node', array_keys($entities['node']));
return node_view_multiple($nodes, 'teaser');

$content_type is the string passed to the menu item.

The code I reported would not use a pager, but it would show all the nodes in a single page.

0

精彩评论

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