dongyou8087 2011-04-08 13:42
浏览 25

Drupal 7 - 如何使用php函数以编程方式在主题模板中插入内容?

I just started working with drupal 7 a week ago, and I have figured out the basics (and the huge differences between drupal 6 vs. 7)

Now, while creating a theme from an html layout the the designer gave me, i have created a few regions, the main menu loads at the top, the content right below etc..

now, at some of the nodes - i need to insert some more dynamic data (e.g. a few divs in different places, each is getting different page content that is created as a page in the CMS backend)

i would really like to know , how can I programmatically add pages and\or any other content (text, image..etc..) created in the cms backend, to my theme's node.

I mean, i have tried to look on google, tried to copy portion of code from the drupal themes which came with the installation etc.. nothing works properly.

pseudo code to what i mean (in case i did not explain my self that good):

load_function('content type' , 'content name')

and use that for an example like this:

load_function('page' , 'about-us');

which will load the about-us content right into where i embed the php code in.

just to remind - i am talking about Drupal 7.

any help will be so much appreciated :)

thank you!

  • 写回答

1条回答 默认 最新

  • dongxia4880 2011-08-01 01:01
    关注
    // Create node object.
    $node = new StdClass();
    $node->type = 'image';
    $node->language = LANGUAGE_NONE;
    node_object_prepare($node);
    
    $node->title = $filepath;    
    
    $node->body[$node->language][0]['value']   = $body_text;
    $node->body[$node->language][0]['summary'] = text_summary($body_text);
    
    node_save($node);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大