Questions tagged [nodes]

The most basic form of content on a Drupal site is a node.

Filter by
Sorted by
Tagged with
69 votes
6 answers
155k views

How do I get the current node ID?

In Drupal 7, if I wanted to get the node id of the currently displayed node (e.g. node/145) I could get it with the arg() function. In this case, arg(1) would return 145. How can I achieve the same ...
dbj44's user avatar
  • 4,734
52 votes
9 answers
63k views

Where is the content of a node's body stored?

In the node table, you'll find everything except the actual body. Where can I find this body text? I'm assuming it's being stored as a blob somewhere.
rockstardev's user avatar
  • 1,039
50 votes
12 answers
22k views

How do I hide nodes that shouldn't be directly accessed from users and search engines?

I've found that there are times I have a node that simply contains content that will be displayed somewhere else, but shouldn't be viewed directly. That is, no one should ever go to node/1234, but the ...
Chaulky's user avatar
  • 6,443
48 votes
7 answers
75k views

How can I programmatically create a node?

How can I programmatically create nodes with date and image fields? I know I can do it in Drupal 7 with the following code. global $user; $node = new stdClass(); $node->title = "YOUR ...
Yuseferi's user avatar
  • 21.8k
43 votes
9 answers
90k views

How can I get the path alias from a node ID or node object?

I have a node object, and I am trying to use it to get a given path in Drupal 8. There was drupal_lookup_path() in Drupal 7 but I'm not seeing any equivalent or documentation for Drupal 8. What's ...
Jack Ryan's user avatar
  • 2,297
41 votes
18 answers
47k views

How to delete all nodes of a given content type?

I have several thousand nodes of a particular content type. Using the web interface (example.com/admin/content), I can only delete about 50 at a time. How can I quickly delete them?
Greg's user avatar
  • 1,076
41 votes
3 answers
55k views

How do I customize the search result page?

I have customized the teaser view of my content types and the page view. Now I need to use the teaser view for the search results page. By default, Drupal displays a full text jumbled mess for each ...
J-Fiz's user avatar
  • 1,353
40 votes
9 answers
33k views

Count of nodes by type [closed]

I am looking for a snippet that lets me display the total count for a specific node type, e.g. "Pages = 167" or "Products = 10630." What code should I use to achieve this?
Diane's user avatar
  • 565
40 votes
11 answers
29k views

How to display a field before node title?

I'm looking to render a certain field before the node's title when displaying a teaser in D7. Effectively I want to go from this to this. I have looked into updating the node.tpl.php but I notice ...
irishbuzz's user avatar
  • 645
40 votes
2 answers
32k views

How to get a node by its url alias?

I know I can load a node by its title with the node_load() function. Is it possible to load a node by its URL alias?
Moon's user avatar
  • 575
37 votes
7 answers
73k views

Get all nodes of given type

I would like to get all nodes that are of my_custom_type type in Drupal 8. I know I can get all the nodes (of any type) with \Drupal\node\Entity\Node::loadMultiple() and the list of all types by \...
PolGraphic's user avatar
  • 1,100
37 votes
5 answers
29k views

Is there a function to get the list of nodes by type?

Is there a function like node_load() that returns a list of nodes by a given content type? I've tried $nodes = node_load(array("type" => 'student_vote')), but it only returns one node. I ...
gmercer's user avatar
  • 843
34 votes
6 answers
38k views

How to load a node based on its title?

I only know the title of a node, and I want to load the node using node_load(). How do I do that?
Dion's user avatar
  • 2,398
34 votes
5 answers
33k views

Node count for taxonomy terms

How can I display the node count values for taxonomy terms with sorting the result list in descending order of node count?
ya.teck's user avatar
  • 5,584
31 votes
7 answers
22k views

How do I let users unpublish and publish their own content?

I want to let users unpublish and publish their own content. By default, you have to give "administer nodes" permission for users to be able to unpublish or publish content. That is way to broad ...
Chaulky's user avatar
  • 6,443
30 votes
3 answers
61k views

How do I get the node URL in a Twig template?

I am trying to get the node URL in a Twig template. {{ content.node_link }} returns the full link, but I only need the URL. How do I retrieve the node URL?
inalto's user avatar
  • 521
27 votes
3 answers
39k views

How to load a node by a field value?

I want to load a certain node. I don't know the id of the node but I do know that it has a certain hash field that is unique and I know that hash. I want to load the node via the hash field. How can ...
Andrew's user avatar
  • 711
27 votes
7 answers
63k views

How to programmatically get the NID of the current node

I've pored over this old thread on drupal.org and it just kind of makes my head spin around. Pulling down the path and trying to parse out the NID from within it? There has to be a better way. And ...
beth's user avatar
  • 9,087
26 votes
4 answers
43k views

Programmatically updating a node

I can create a node using the following code: $node = \Drupal::entityTypeManager()->getStorage('node')->create($array); But if I have the node ID, how can I edit a node?
BOES's user avatar
  • 1,023
25 votes
4 answers
25k views

How can I get the node ID from a path alias?

I want to be able to get the nid but the only information I have is http://example.com/this-is-the-alias. Is there a way to get either the internal path of /node/* for that alias if I am not on the ...
BrandenB171's user avatar
  • 1,112
25 votes
14 answers
13k views

How do I hide the default page /node?

Drupal out of the box comes with a page (which is the default homepage) that is assigned to the node path. How do I avoid users reach it, and redirect them to the actual homepage of the site?
wiifm's user avatar
  • 5,290
25 votes
6 answers
27k views

Programmatically attaching files

I have created the "Gallery" content type, and added two fields: "photo," and "document." I then used the following code for uploading a file in the "document" field: $file = file_save_upload('...
Vinodkumar SC's user avatar
24 votes
10 answers
34k views

How do I change the machine name of a field once it's been created

I spaced out while typing the field name an now the machine name is not what I wanted it to be. I know it's just an annoyance. but I'm wondering if there is some way to alter the machine name of a ...
user379468's user avatar
  • 2,520
23 votes
2 answers
23k views

How to iterate over all the nodes from a content type

I want to recover some info from a field of all the nodes of a specific content type. I know how to do it using a db_query and getting all the node ID then iterate over them. What I would like to know ...
drcelus's user avatar
  • 1,652
23 votes
5 answers
8k views

Unable to delete feature content type after uninstalling feature

Issue Uninstalling a feature which creates a content type hides the "Delete" link on the admin/structure/types. Issue on Drupal.org
Aram Boyajyan's user avatar
22 votes
7 answers
17k views

How to programmatically set the front page?

I want to set the Drupal front page programmatically at run time. How can I do this? Is this possible?
radu c's user avatar
  • 4,350
21 votes
4 answers
33k views

How to import / export content type?

In Drupal 6 we had content type export import, I cannot find this in Drupal 7. Any tips please?
giorgio79's user avatar
  • 4,597
20 votes
6 answers
14k views

How do I implement two-way node references?

The node-reference module (a component of CCK) provides a great way to create a reference one node from another. What is the best way to expose a two-way relationship between the two? Example below: ...
markdorison's user avatar
  • 5,574
20 votes
7 answers
15k views

fast saving single field value

I've got around 70k nodes of specified type on my site. I need to run an update on them. Some operations and setting one field to desired value. node_save is really slow and it causes crashes (too ...
Eloar's user avatar
  • 303
20 votes
4 answers
32k views

How do I add additional view modes for a node?

I am creating a custom content type. By default, nodes support only two view modes (full and teaser): function mymodule_view($node, $view_mode) { if ($view_mode == 'full') { $node->...
werqious's user avatar
  • 750
20 votes
4 answers
11k views

Relation vs. References vs. Entity Reference for managing node-reference-type relationships

References Entity Reference Relation It seems like there are several active modules that all have similar functionality. Can anyone offer any information as to which branch appears to be the most ...
starsinmypockets's user avatar
20 votes
1 answer
16k views

How do I get the name of the content type?

in Drupal 7, which function do I need to call to get the name of the content type? I have the $node object and I also have the id of the content type if I use $node->type. But I need to get the ...
Marcos Buarque's user avatar
19 votes
7 answers
23k views

How to copy content type?

How to copy content type in Drupal 7 ? I can't find a button to duplicate content type.
Raptor's user avatar
  • 393
19 votes
3 answers
16k views

Embed a "node add" form in a page

I'm looking for a way to embed a "node add" form on a landing page. I was using Form Block, but it appears to bring many error because I was using a development snapshot version.
ousneo's user avatar
  • 325
19 votes
3 answers
29k views

What hook can I use for post-save actions?

I've found several posts with this same question, but the answers always diverge to some other topic or they don't work for my needs. After a node is saved, I want my custom module to insert a row ...
Kenny Wyland's user avatar
  • 3,058
19 votes
8 answers
19k views

Limit which roles can view a node basing on its content type

I'm using Drupal 7 and I created a new content type called "eBook," and I created a new role called "MonthlySubscriber." My intention is to allow only users with the "MonthlySubscriber" to view the "...
John's user avatar
  • 1,491
18 votes
5 answers
17k views

Get the list of all content types

How do I get a list of all the content types defined in a Drupal 8 site? In Drupal 7 it used to be node_type_get_types(), but it has been deprecated. I tried Entity::loadMultiple() but it doesn't ...
pbonnefoi's user avatar
  • 1,816
18 votes
5 answers
14k views

Why can't I delete certain content types?

I have a Drupal 7 site, and under the Content Types menu, only certain types have a 'delete' link under the 'Operations' column. All of the content types have the links for 'edit', 'manage fields', ...
user1359's user avatar
  • 3,909
18 votes
4 answers
17k views

How do I remove the "submitted by" text on node display?

In Drupal 6 the option to remove that text was located in the theme settings; where is it in Drupal 7?
J-Fiz's user avatar
  • 1,353
18 votes
5 answers
26k views

Is it possible to restore a deleted node?

While revisions are kept and it is easy to get back to a previous revision of a node, I was wondering if it is possible to restore a node that has really been deleted by a user?
Palmin's user avatar
  • 383
18 votes
4 answers
22k views

How to set a taxonomy term programmatically for a node?

I created taxonomy terms and assigned it to a content type 'Article' using term reference field. I created nodes by programmatically but how to set taxonomy terms for the nodes? The taxonomy terms ...
Ranjani's user avatar
  • 561
18 votes
2 answers
14k views

How to get the human readable content type name in a node template

I have created node template for my node, and its working fine. I need to print content type name, which is like "Whitepaper" and has machine name "w1" in my node template. If I use variable {{ node....
Dev's user avatar
  • 731
18 votes
5 answers
19k views

How I can delete all node/field revisions?

I have a drupal 7 sites, where it keeps node and field revisions. I keep revisions for the case where by mistake a new faulty version is saved and I want to revert back. But, now I want to clean and ...
john's user avatar
  • 1,601
18 votes
8 answers
10k views

"View unpublished content" permission for non-author

I googled a bit to see if there's a permission-level way to allow a logged-in (but non-admin) user see unpublished content (marked with the CSS node-unpublished class). This appears to be scheduled ...
no more drupal's user avatar
17 votes
2 answers
13k views

How can I detect when a node is changed from 'Published' to 'Unpublished'?

In hook_node_update(), I can easily tell the 'status' of a node (whether it's published or not) after it's been updated. However, is there an easy way to check to see if the updated node was ...
geerlingguy's user avatar
  • 5,483
17 votes
9 answers
26k views

How can I create a view of child nodes based on the menu relationship?

Say you have the following pages in a menu tree: Projects Project One Project Two Project Three I'm looking for a way to create a view that will be embedded in the Project (parent) page that will ...
Camsoft's user avatar
  • 3,139
17 votes
6 answers
7k views

View of users flagged by a user, users flagging a user, and nodes from users flagged by a user

I have a user flag that is pretty much like a "follow" or "subscribe" function. Basically I want to create 3 views for my website's user profile pages: A list of users flagged by a user (e.g. a ...
Jamie Chang Liu's user avatar
17 votes
1 answer
773 views

Sharing content with domain access?

I setup a site with domain access. It has 2 subsites. I want to publish content from the main site to the subsites. This is already working good with send to affiliates. But I want some local admins ...
oll's user avatar
  • 724
16 votes
1 answer
1k views

How to correctly remove a module in a staged environment?

Some modules have deïnstallation routines. Which typically remove databasetables for that module, variables from the variable table and locales introduced by that module. These routines live in the ....
berkes's user avatar
  • 3,100
15 votes
6 answers
18k views

How to embed a view in a specific node?

I try to embed a view in a specific node. I found tutorials for doing this with Drupal 7 and PHP-Templates: <?php print views_embed_view('view_name'); ?> But I look for a way in Drupal 8 with ...
TiMESPLiNTER's user avatar

1
2 3 4 5
151