Giter Club home page Giter Club logo

Comments (7)

joyqi avatar joyqi commented on June 9, 2024

目前似乎没有特别的办法,不过可以考虑加上一个

from typecho.

Moidea avatar Moidea commented on June 9, 2024

有过类似功能我是使用你之前用过的方法实现的:
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('PostFields_Plugin', 'new_fields');
直接在PostFields_Plugin里隐藏页面不想显示的字段
算是一个折中的办法

from typecho.

jrotty avatar jrotty commented on June 9, 2024

折中方案还有用js判断插😄,还有就是希望字段值为空的字段不要也一股脑塞进数据库,字段值为空应该就是没用到,塞进数据库感觉徒增无用数据

from typecho.

Moidea avatar Moidea commented on June 9, 2024

可能我的字段都属于不确定性的,后期可能有些页面也会用到,所以暂时都保留了,如果不想要空字段可以直接给主题设置一个按钮专门处理数据库中的fields表的空字段

from typecho.

xiamuguizhi avatar xiamuguizhi commented on June 9, 2024

@chatgtp4

你可以通过检查 $layout 对象的某些属性来判断当前是否在文章编辑页面。在 Typecho 中,$layout 对象通常是 Widget_Archive 的一个实例,它有一个属性 is 可以用来检查当前的页面类型。

以下是一个示例,这个函数只会在文章编辑页面下插入自定义字段:

function themeFields($layout) {
    // 检查是否为文章编辑页面
    if ($layout->is('post')) {
        $Pictype= new Typecho_Widget_Helper_Form_Element_Select('Pictype',array(
            '-1' => _t('无图'),
            '0' => _t('默认文图'),
            '1' => _t('多图样式'),
            '2' => _t('动态样式')),
            '0',_t('列表样式'),_t("文章类表样式,不填写文章头图时则不显示图片"));
        $layout->addItem($Pictype);
    }
}

在这个例子中,$layout->is('post') 会检查当前页面是否是文章编辑页面。如果是,就会执行后面的代码,添加自定义字段。如果不是(例如是独立页面编辑页面或其他页面),就不会执行后面的代码,所以不会添加自定义字段。

注意:$layout->is('post') 可能在某些情况下并不能正确判断是否为文章编辑页面,具体取决于 Typecho 的版本和设置。如果这个方法不起作用,你可能需要查找其他的判断方法。

from typecho.

cuixiping avatar cuixiping commented on June 9, 2024

function themeFields($layout) 函数中添加的自定义字段, 为什么没有参数指定字段值的类型(str/int/float/json) ?
而自带的自定义字段却有类型, 这里是否有问题?

from typecho.

cuixiping avatar cuixiping commented on June 9, 2024

建议在主题自定义字段的 label 前面增加1个复选框, 勾选之后表示记录该字段, 才会塞进数据库, 不勾选则不进数据库.

from typecho.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.