PolyCMS Template Tags & Helper Functions
Overview
PolyCMS provides a comprehensive set of helper functions (template tags) available in theme templates and plugins. These functions simplify common operations like URL generation, content retrieval, and menu rendering.
URL Functions
polycms_blog_url()
Returns the base URL of the blog frontend.
$url = polycms_blog_url();
// Output: https://yourdomain.com/blog
polycms_post_url($post)
Generates the full frontend URL for a post.
$url = polycms_post_url($post);
// Output: https://yourdomain.com/blog/my-first-post
polycms_category_url($category)
Generates the archive URL for a category.
$url = polycms_category_url($category);
// Output: https://yourdomain.com/blog/category/web-development
polycms_tag_url($tag)
Generates the archive URL for a tag.
$url = polycms_tag_url($tag);
// Output: https://yourdomain.com/blog/tag/php
Content Retrieval
polycms_get_post($id)
Retrieves a single post by ID.
$post = polycms_get_post(42);
echo $post->title;
echo $post->content_html;
polycms_get_posts($args)
Retrieves a collection of posts with filtering options.
$posts = polycms_get_posts([
'status' => 'published',
'category_id' => 5,
'limit' => 10,
'order_by' => 'created_at',
'order' => 'DESC',
]);
polycms_get_post_meta($post_id, $key, $default = '')
Retrieves a custom meta value for a post.
$reading_time = polycms_get_post_meta($post->id, 'reading_time', '5 min');
polycms_get_categories($args)
Retrieves categories with optional filtering.
$categories = polycms_get_categories([
'parent_id' => null, // Top-level only
'order_by' => 'name',
]);
polycms_get_tags()
Retrieves all tags.
$tags = polycms_get_tags();
Rendering Functions
polycms_render_menu($location)
Renders a navigation menu assigned to the specified location.
polycms_render_menu('primary');
// Outputs: <nav><ul><li><a href="...">Home</a></li>...</ul></nav>
polycms_render_widget_area($area_id)
Renders all widgets assigned to a Widget Area.
polycms_render_widget_area('blog-sidebar');
polycms_render_shortcodes($content)
Processes and replaces all shortcodes in the given content string.
$rendered = polycms_render_shortcodes($post->content_html);
SEO Functions
polycms_get_meta_title($content)
Returns the computed meta title for a post or page.
$title = polycms_get_meta_title($post);
polycms_get_meta_description($content)
Returns the meta description for a post or page.
$desc = polycms_get_meta_description($post);
Theme Functions
polycms_get_theme_option($key, $default = '')
Retrieves a Theme Option value set by the site administrator.
$logo_url = polycms_get_theme_option('logo_url', '/assets/default-logo.png');
$primary_color = polycms_get_theme_option('primary_color', '#333333');
polycms_get_active_theme()
Returns information about the currently active theme.
$theme = polycms_get_active_theme();
echo $theme->name;
echo $theme->version;
Hook Functions
polycms_add_action($hook, $callback, $priority = 10, $args = 1)
Registers an action hook callback.
polycms_add_filter($hook, $callback, $priority = 10, $args = 1)
Registers a filter hook callback.
polycms_do_action($hook, ...$args)
Fires an action hook, executing all registered callbacks.
polycms_apply_filters($hook, $value, ...$args)
Applies all registered filter callbacks to a value and returns the result.
For complete hook documentation, see the Hooks & Filters Reference.
Utility Functions
polycms_validate_file_path($path)
Validates a file path to prevent directory traversal attacks. Returns true if the path is safe.
polycms_get_setting($key, $default = '')
Retrieves a CMS setting value from the blog_settings table.
$posts_per_page = polycms_get_setting('posts_per_page', 10);
Need Help?
Need guidance implementing template tags in your custom theme or plugin? Reach out through our CodeCanyon page. We offer completely free developer support for all PolyCMS customers.
Related Documentation
- Building a Custom Theme — Use template tags in theme files.
- Building a Custom Plugin — Use helper functions in plugin code.
- Hooks & Filters Reference — Complete hook API documentation.