首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >节点保存状态

节点保存状态
EN

Stack Overflow用户
提问于 2012-04-30 20:39:28
回答 1查看 369关注 0票数 0

我尝试添加未发布的新节点。

我设置状态= 0;

但当检查此节点时,状态= 1;

此代码。

代码语言:javascript
复制
$node = new StdClass();
                $node->type = 'article'; //giving it type
                $node->title = $article->headline; //gives title
                $node->body = $article->body; //gives body

                $node->field_abstract[0]['value'] = $article->summary;
                $node->field_is_syndigate[0]['value'] = 1;
                $node->field_syndigate_first_time[0]['value'] = 1;

                $node->language = $language->language; //'en' or 'ar'
                $node->comment = 2; //read&write comment

                //$node->created = $article->parsed_at;
                $node->created = '';
                $node->changed = $node->created;
                $node->status = 0;
                $node->promote = 0;
                $node->sticky = 0;
                $node->format = 4; // Editor Filtered HTML
                $node->uid = $user->uid;

                //$node->field_attribution[0]['value'] = $article->copyright; // attribution
                $attribution = '';
                if($article->logo_path){
                    $attribution = '<img src="http://pub.syndigate.info/logos/small/'.$article->title_id.'.png" title="'.$article->title_name.'" border="0" />';
                    if($article->website){
                        $attribution = '<a href="'.$article->website.'" title="'.$article->title_name.'" target="_blank">'.$attribution.'</a>';
                    }
                    $attribution .= ' ';

                }
                $attribution .= $article->copyright;
                $node->field_attribution[0]['value'] = $attribution; // attribution
                $node->field_source[0]['value'] = $article->title_id; // source
                node_save($node);

如何将节点保存为未发布。

EN

回答 1

Stack Overflow用户

发布于 2012-04-30 23:06:41

以编程方式创建节点时,需要设置

代码语言:javascript
复制
$node->is_new = TRUE; 

如果您将$node->created设置为空值,我建议您删除脚本中的这一行,node_save()会处理它。与$node->changed相同,因为您提供了相同的值,只需从脚本中删除此行即可

希望这对你有所帮助

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10383856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档