Coder Social home page Coder Social logo

dexit / newspack-sponsors Goto Github PK

View Code? Open in Web Editor NEW

This project forked from automattic/newspack-sponsors

1.0 1.0 0.0 5.18 MB

Create sponsors and associate them with posts, categories, and tags.

License: GNU General Public License v2.0

JavaScript 23.07% PHP 76.76% SCSS 0.18%

newspack-sponsors's Introduction

newspack-sponsors

semantic-release newspack-sponsors

Create sponsors, edit sponsor info, and associate sponsors with posts, categories and tags. Allows special visual treatment for sponsored content.

Usage

  1. Activate this plugin.
  2. In the WP admin dashboard, look for Sponsors.
  3. Create and publish sponsors here. Add required info (content, sponsor logo, sponsor URL and byline prefix).
  4. Once at least one sponsor has been published, you can assign sponsors directly to posts in the post edit screen. This is known as a direct sponsorship.
  5. You may also assign categories and tags to a sponsor in the edit screen for a particular sponsor. This is known as a category or tag sponsorship. The sponsor will be associated with all posts that have those categories or tags.

Development

Run composer update && npm install.

Run npm run build.

To use in a theme, check for the existence of the helper function first. Then call the helper function, optionally passing the ID of the post or term and the scope of the sponsors you want to get (if you don't provide params, the function will attempt to guess based on the current page):

if ( function_exists( '\Newspack_Sponsors\get_all_sponsors' ) ) {
	$sponsors = \Newspack_Sponsors\get_all_sponsors( get_the_ID(), 'native', [ 'maxwidth' => 130, 'maxheight' => 45 ] );
	var_dump( $sponsors );
}

Both helpers can be called from anywhere with a single argument with the post ID or term ID. If calling within a single post or archive page, the argument is optional and the current post ID or archive term ID will be used.

Both helpers will return an array containing all sponsors that are associated with the post or archive, and all info needed to display assets for each sponsor on the front-end. If the same sponsor applies as both a direct sponsor and a category or tag sponsor, that sponsor will appear multiple times but with the corresponding type in each case. Data returned for each sponsor:

  • sponsor_type - Type of sponsorship: direct, category, or tag.
  • sponsor_scope - The scope of sponsorship: native or underwritten. The distinction may differ between publishers, but this allows a different visual treatment for each.
  • sponsor_id - Post ID of the sponsor in WP, in case you need to fetch more info on it.
  • sponsor_name - Display name of the sponsor. This is the post_title of the sponsor.
  • sponsor_slug - Slug of the sponsor. This is the post_name of the sponsor.
  • sponsor_blurb - Content which can be displayed with any sponsored post. This is the content of the sponsor.
  • sponsor_url - A URL to link to when displaying the Sponsor Name on the front-end.
  • sponsor_byline - The copy shown in lieu of a byline on sponsored posts. This is combined with the sponsor_name to form a full byline. (Default: “Sponsored by” or “Paid for by”)
  • sponsor_logo - Object containing properties for a medium-sized image to be displayed with any sponsored post. This is the thumbnail of the sponsor. Contains src, img_width and img_height properties.
  • sponsor_flag - The label that appears in lieu of a category tag for sponsored content. This can be set site-wide and overridden per sponsor.
  • sponsor_disclaimer - The disclaimer that explains sponsored content. This can be set site-wide and overridden per sponsor.

newspack-sponsors's People

Contributors

dependabot[bot] avatar dkoo avatar semantic-release-bot avatar adekbadek avatar miguelpeixe avatar matticbot avatar leogermani avatar thomasguillot avatar claudiulodro avatar laurelfulford avatar

Stargazers

Rihards Mantejs avatar

Watchers

 avatar

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.