当我想在不使用循环的情况下显示单个帖子时,我使用这个:post_title;?>问题是当我移动网站时,id通常会改变。有没有办法通过slug查询这个帖子? 最佳答案 来自WordPress法典:$the_slug,'post_type'=>'post','post_status'=>'publish','numberposts'=>1);$my_posts=get_posts($args);if($my_posts):echo'IDonthefirstpostfound'.$my_posts[0]->ID;endif;?>WordP
当我想在不使用循环的情况下显示单个帖子时,我使用这个:post_title;?>问题是当我移动网站时,id通常会改变。有没有办法通过slug查询这个帖子? 最佳答案 来自WordPress法典:$the_slug,'post_type'=>'post','post_status'=>'publish','numberposts'=>1);$my_posts=get_posts($args);if($my_posts):echo'IDonthefirstpostfound'.$my_posts[0]->ID;endif;?>WordP
当我阅读Django代码时,我经常在模型中看到所谓的“slug”。我不太确定这是什么,但我知道它与URL有关。这个蛞蝓应该如何以及何时使用?(我在thisglossary中阅读了它的定义。)SlugAshortlabelforsomething,containingonlyletters,numbers,underscoresorhyphens.They’regenerallyusedinURLs.Forexample,inatypicalblogentryURL:https://www.djangoproject.com/weblog/2008/apr/12/spring/thela
当我阅读Django代码时,我经常在模型中看到所谓的“slug”。我不太确定这是什么,但我知道它与URL有关。这个蛞蝓应该如何以及何时使用?(我在thisglossary中阅读了它的定义。)SlugAshortlabelforsomething,containingonlyletters,numbers,underscoresorhyphens.They’regenerallyusedinURLs.Forexample,inatypicalblogentryURL:https://www.djangoproject.com/weblog/2008/apr/12/spring/thela
HowbesttogettheslugofanobjectfromaListviewintoaDjangoform我有一个DjangoListView/FormView组合,其中页面列表中的每个对象都有一个用于切换模式表单的按钮。表单有一个隐藏字段,我想用它来自的列表中的对象的slug预填充它(即,不是页面的slug,而是该页面上列表中的对象)。我能想到的一种方法是让{{form}}标记以某种方式接受对象的slug作为参数-例如{{formobject_instance=object.slug}}。我该怎么做?我如何在ListView中调用它?感谢您提供的任何意见。您可以创建一个自定义过滤器来
HowbesttogettheslugofanobjectfromaListviewintoaDjangoform我有一个DjangoListView/FormView组合,其中页面列表中的每个对象都有一个用于切换模式表单的按钮。表单有一个隐藏字段,我想用它来自的列表中的对象的slug预填充它(即,不是页面的slug,而是该页面上列表中的对象)。我能想到的一种方法是让{{form}}标记以某种方式接受对象的slug作为参数-例如{{formobject_instance=object.slug}}。我该怎么做?我如何在ListView中调用它?感谢您提供的任何意见。您可以创建一个自定义过滤器来