Zum Inhalt springen
nnhelpers for WordPress

nnhelpers for WordPress

A toolbox-plugin with a huge collection of one-liners to drastically speed up your plugin-development

About

  • What is nnhelpers?

Getting started

  • Installation
  • Creating a plugin

Custom Post Types (CPT)

  • Creating a Custom Post Type (CPT)
  • Adding forms and fields to your CPT
  • Adding forms and fields to WordPress posts
  • CPT – field types and configurations

Custom Widgets and Blocks

  • Creating a custom widget for Elementor

Basic Concepts

  • QueryBuilder
  • Model
  • Repository
  • Fluid Templates
  • Creating custom ViewHelpers
  • Home
  • Docs
  • Basic Concepts
  • Model

Model

Table of Contents
  • Domain-Models in WordPress
    • Example Model
    • Inherited propertes from AbstractModel
      • Overview:
    • Accessing properties in your Fluid-template
Table of Content

Domain-Models in WordPress #

When you use a nnhelpers-Repository to retrieve entries from the database, the data will automatically be mapped to a Model.

Please refer to the Repository docs to find out, how to create the Repository for the Model.

Example Model #

Your Model should always extend the \Nng\Nnhelpers\Domain\Model\CPT\AbstractModel

<?php

namespace My\Extension\Domain\Model\CPT;

use Nng\Nnhelpers\Domain\Model\CPT\AbstractModel;

class Entry extends AbstractModel
{
    // auto-mapped from `post.post_title`
    public $postTitle;

    // auto-mapped from the `postmeta._extname_entry_www`
    public $www;

    /**
     * Example for a computed property
     * In your Fluid-template you can access it like any
     * other property of the model, e.g. `item.example`
     */
    public function getExample() {
        return 'works!';
    }

}

Inherited propertes from AbstractModel #

The properties inherited from Nng\Nnhelpers\Domain\Model\CPT\AbstractModel are:

  • All fields from the post-entry with a lowerCamelCase key. This means that post_title will be accessible as the property postTitle in the Model
  • The media attached to the WP-Post in the Array media and the first media element in firstMedia.
  • The categories of the WP-Post in the Array category

Overview: #

property type description
ID integer ID of the WP-Post
postTitle string Title (post_title) of the WP-Post
postAuthor string Author (post_author) of the WP-Post
... ... ... and so on. All fields from post-table
media Array<SysFile> All media (images) related to the Post
firstMedia SysFile The first media / image of the Post
categories Array<Array> List of categories related to Post

Accessing properties in your Fluid-template #

All properties in the Model can be accessed from Fluid using the dot-syntax. It plays no role, if the properties are static or computed with a getter.

    <f:for each="{entries}" as="{entry}">
        <h1>{entry.postTitle}</h1>
        <f:image src="{entry.firstMedia}" maxWidth="300" />
    </f:for>
Share This Article :
  • Facebook
  • Twitter
  • LinkedIn
  • Pinterest
Still stuck? How can we help?

How can we help?

Updated on 2. Juli 2022
QueryBuilderRepository

Powered by BetterDocs

Table of Contents
  • Domain-Models in WordPress
    • Example Model
    • Inherited propertes from AbstractModel
      • Overview:
    • Accessing properties in your Fluid-template
nnhelpers for WordPress
Mit Stolz präsentiert von WordPress.