npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ctng/wordpress

v5.0.2

Published

<section>

Downloads

3

Readme

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)