5.0.2 • Published 3 years ago

@ctng/wordpress v5.0.2

Weekly downloads
12
License
MIT
Repository
github
Last release
3 years ago

Wordpress Package

Installation


Run npm install @ctng/wordpress. The services of the Wordpress Module are providedIn: 'root'. There is no module to import. Just inject the services in components, services, pipes or something else.

Configuration


The Wordpress Package needs a configuration, which can be provided by the InjectionToken WP_CONFIG (see below).

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
  ],
  providers: [
    { provide: WP_CONFIG, useValue: { protocoll: 'http://', domain: 'localhost:8080' } },
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

The configuration is defined by the WordpressConfig interface:

export interface WordpressConfig {
  protocoll: string;
  domain: string;
  subDomain?: string;
}

Services


The package contains the following services:

WPDataService


This is the main service to fetch / set data from / to Wordpress.

getOption(option: string, lang?: string): Observable

option: This is the name of the acf option fields as string
lang(optional): WPLanguage enum, which defines the language to fetch

return: Observable of the option

getPosts(queryArgs: WPQueryParams = null): Observable<T[]>

queryArgs(optional): WPQueryParams object for specific query parameters in Wordpress

return: Observable of the posts as list

getPages(queryArgs: WPQueryParams = null): Observable<T[]>

queryArgs(optional): WPQueryParams object for specific query parameters in Wordpress

return: Observable of the pages as list

getCustomPosts(customType: string, queryArgs: WPQueryParams = null): Observable<T[]>

customType: Name of the custom post type
queryArgs(optional): WPQueryParams object for specific query parameters in Wordpress

return: Observable of the posts as list

getCustomPostById(customType: string, id: number, queryArgs: WPQueryParams = null): Observable

customType: Name of the custom post type
id: ID of specific post
queryArgs(optional): WPQueryParams object for specific query parameters in Wordpress

return: Observable of the post

WpQueryService


This service maps the WPQueryParams object to the request url of wordpress. This services is normally not needed outside of the WPDataService.

mapQueryToUrl(queryParams: WPQueryParams): string

queryArgs: WPQueryParams object for specific query parameters in Wordpress

return: Wordpress query url based on the WordpressConfig and the given WPQueryParams

UrlService


This service returns urls, which are needed for fetching data from Wordpress. The urls are constructed based on the WordpressConfig and the Wordpress Rest Urls.

getBaseUrl(): string

return: Base url of the Wordpress domain

getWordpressRestUrl(apendix: string = null): string

appendix(optional): Appendix for the Endpoint (e.g. posts, pages, ...)

return: The Rest endpoint of Wordpress

getWordpressAcfRestUrl(apendix: string = null): string

appendix(optional): Appendix for the Endpoint

return: The ACF Rest endpoint of Wordpress

Models


The following interfaces are defined based on the Wordpress model

WPPost

This contains all fields of a Wordpress post

WPQueryParams

This interface contains the most used query params for fetching data from Wordpress

export interface WPQueryParams {
  status?: string;
  include?: number[];
  page?: number;
  perPage?: number;
  order?: WPOrder;
  orderBy?: string;
  language?: WPLanguage;
}

WPImage

Contains all fields for a Wordpress image

WPLinkedPost

Contains fields for a fields, which is linked to another post

Query Enums


WPLanguage

Defines the language, which should be fetched

WPOrder

Defines the order for sorting the posts (e.g. ascending)

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

4 years ago

4.0.0

4 years ago

3.0.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago