Classes – Conductor https://conductorplugin.com Content blocks for WordPress Mon, 30 Jan 2017 14:26:01 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.5 Class: Conductor_Widget_Default_Query https://conductorplugin.com/docs/classes/class-conductor-widget-default-query/ Tue, 09 Feb 2016 16:37:25 +0000 http://conductorplugin.com/?post_type=docs&p=10381 This is the default class for querying and displaying content within Conductor Widgets. It contains logic to create/execute queries using the WP_Query class.

The post Class: Conductor_Widget_Default_Query appeared first on Conductor.

]]>
Description

This is the default class used for querying and also displaying content within Conductor Widgets. By default, if the conductor_widget_query filter value returns false (Boolean), this class is used in Conductor Widgets.

Construct/Instantiation

Upon instantiation, all default logic found in the Conductor_Widget_Query class is run.

A filter is added to found_posts to ensure the correct number of results are returned for more advanced queries. This logic is only executed on Conductor Widget queries. The number of found posts is adjusted if any of the following are true:

  • The offset query argument is set to a value greater than 1
  • Specific post IDs are included via the post__in query argument
  • Specific post IDs are excluded via the post__not_in query argument
  • The number of found posts is greater than the max_num_posts query argument

The number of found posts for Conductor Widgets is passed to the conductor_query_found_posts filter.

Conductor_Widget_Default_Query::query()

This function is performs a query using WP_Query and the Conductor Widget instance data. The query arguments are passed to the conductor_query_args filter before the query is executed.

Conductor_Widget_Default_Query::next_post()

This function advances the current query to the next post using WP_Query::next_post(). The conductor_query_next_post action is also triggered.

Conductor_Widget_Default_Query::the_post()

This function advances the current query to the next post and also sets up global post variables using WP_Query::the_post(). The conductor_query_the_post action is also triggered.

Conductor_Widget_Default_Query::get_pagination_links()

This function fetches pagination links for the current query and outputs them. It uses paginate_links() to generate the pagination links.

Conductor_Widget_Default_Query::get_excerpt_by_id()

This function fetches an excerpt for the current post. The content is passed to the the_content filter before it is returned.

Conductor_Widget_Default_Query::get_content_by_id()

This function fetches content for the current post. The content is passed to the the_content filter before it is returned.

 

This class is instantiated when the Conductor_Widget::widget() function is called (when a Conductor Widget is displayed on the front-end).

Output Element Callback Functions

Conductor_Widget_Default_Query::conductor_widget_featured_image()

This function outputs the featured image for the current post. The conductor_widget_featured_image_before action is triggered before the featured image output. The featured image size is passed to the conductor_widget_featured_image_size filter before it is rendered. The conductor_widget_featured_image_after action is triggered after the featured image output.

Conductor_Widget_Default_Query::conductor_widget_post_title()

This function outputs the post title for the current post. The conductor_widget_post_title_before action is triggered before the post title output. Output element data is used to determine if the post title should be linked to the post. The conductor_widget_post_title_after action is triggered after the post title output.

Conductor_Widget_Default_Query::conductor_widget_author_byline()

This function outputs the author byline for the current post. The conductor_widget_author_byline_before action is triggered before the author byline output. The author byline consists of the author’s display name wrapped in a link to the author’s posts and the date. The conductor_widget_author_byline_after action is triggered after the author byline output.

Conductor_Widget_Default_Query::conductor_widget_post_content()

This function outputs the post content (or excerpt) for the current post. The conductor_widget_post_content_before action is triggered before the post content output. The content_display_type widget setting is used to determine which type of content (excerpt or content) should be output. The conductor_widget_post_content_after action is triggered after the post content output.

Conductor_Widget_Default_Query::conductor_widget_read_more()

This function outputs the read more link for the current post. The conductor_widget_read_more_before action is triggered before the read more output. Output element data is used to determine if the read more element should be linked to the post. The conductor_widget_read_more_after is triggered after the read more output.

Technical Details

Resources

The post Class: Conductor_Widget_Default_Query appeared first on Conductor.

]]>
Class: Conductor_Widget_Query https://conductorplugin.com/docs/classes/class-conductor-widget-query/ Mon, 08 Feb 2016 21:07:43 +0000 http://conductorplugin.com/?post_type=docs&p=10361 This is the foundation query class used in Conductor Widgets. It is used primarily for displaying content within Conductor Widgets and contains the structure for querying content.

The post Class: Conductor_Widget_Query appeared first on Conductor.

]]>
Description

This is the foundation query class used in Conductor Widgets. It is used as a base class to initialize logic used for displaying content (output elements) within Conductor Widgets and it contains the structure/helper functions for querying content.

Developers should extend this class to create their own query functionality/logic (see examples below and Conductor_Widget_Default_Query).

Construct/Instantiation

Upon instantiation, arguments are processed and stored as properties on the class. Only valid arguments (variables existing on the class) are stored. All other arguments will not be stored.

After the arguments have been processed, if a Conductor Widget instance exists (via arguments), the query is run (Conductor_Widget_Query::query()).

Output element callback functions are hooked to the conductor_widget_display_content_{$this->number} action. Opening/closing wrapper and content wrapper element callback functions are also hooked (before and after sortable output elements).

By default, the opening wrapper element is hooked at priority of 1 and the opening content wrapper element is hooked at a priority of 2 (right after opening wrapper element). The closing content wrapper element is hooked at a priority of 999 and the closing wrapper element is hooked at priority of 1000 (right after closing content wrapper element).

By default, sortable output elements will always start at a priority of 10 and increase by 10 (i.e. 10, 20, 30, 40, 50, etc…). This allows for an almost infinite number of other elements to be added (hooked) between the default priorities. The default priority step size of 10 can be adjusted in the conductor_widget_admin_localize filter via the priority_step_size property.

The default Conductor Widget callback functions are hooked in this order:

  • Conductor_Widget_Query::conductor_widget_wrapper() – priority: 1
  • Conductor_Widget_Query::conductor_widget_content_wrapper() – priority: 2
  • Conductor_Widget_Query::conductor_widget_featured_image() – priority: 10
  • Conductor_Widget_Query::conductor_widget_post_title() – priority: 20
  • Conductor_Widget_Query::conductor_widget_author_byline() – priority: 30
  • Conductor_Widget_Query::conductor_widget_post_content() – priority: 40
  • Conductor_Widget_Query::conductor_widget_read_more() – priority: 50
  • Conductor_Widget_Query::conductor_widget_content_wrapper_close() – priority: 999
  • Conductor_Widget_Query::conductor_widget_wrapper_close() – priority: 1000

When an output element is hooked to the conductor_widget_display_content_{$this->number} action, Conductor_Widget_Query triggers both the conductor_widget_query_add_display_content and conductor_widget_query_add_display_content_{$widget_number} actions.

The Conductor_Widget_Query will first look for callback functions presented as an array, which are callable, on a class (can be any PHP class as long as the callback method exists) which isn’t and instance of the Conductor_Widget_Query class (i.e. an object-oriented approach).

If a valid callback function isn’t found there, it will then look for a callback function on itself (a function which matches the callback name within the Conductor_Widget_Query class).

Lastly, the logic will check to see if a stand-alone callback function (not within a PHP class) exists.

Note: By default, if Conductor_Widget_Query detects that an output element should not be visible/displayed, the output element will be ignored.

Note: By default, if Conductor_Widget_Query does not find a valid callable callback function, the output element will be ignored.

Note: By default, Conductor Widget callback functions are prefixed with conductor_widget_ (i.e. the featured_image output element callback function is: conductor_widget_featured_image). This value can be modified via the conductor_widget_query_callback_prefix filter.

Conductor_Widget_Query::query()

This function is meant to perform a query and return query results (optional).

Note: Developers must create their own version of this function in their custom Conductor Widget Query sub-class.

Conductor_Widget_Query::get_query()

This function returns the current query object (stored in Conductor_Widget_Query->query).

Conductor_Widget_Query::have_posts()

This function is meant to check if the current query has any posts.

Note: Developers must create their own version of this function in their custom Conductor Widget Query sub-class.

Conductor_Widget_Query::next_post()

This function is meant to advance the current query to the next post.

Note: Developers must create their own version of this function in their custom Conductor Widget Query sub-class.

Conductor_Widget_Query::the_post()

This function is meant to advance the current query to the next post and also setup global post variables.

Note: Developers must create their own version of this function in their custom Conductor Widget Query sub-class.

Conductor_Widget_Query::get_current_post()

This function is meant to get the current post object reference within the query.

Note: Developers must create their own version of this function in their custom Conductor Widget Query sub-class.

Conductor_Widget_Query::get_pagination_links()

This function is meant to get pagination links for the current query and output them.

Note: Developers must create their own version of this function in their custom Conductor Widget Query sub-class.

 

This class is instantiated when the Conductor_Widget::widget() function is called (when a Conductor Widget is displayed).

Technical Details

Resources

Examples

The following example demonstrates how to extend Conductor_Widget_Query and create custom logic for querying content.



The post Class: Conductor_Widget_Query appeared first on Conductor.

]]>