grottopress/wordpress-posts
Composer 安装命令:
composer require grottopress/wordpress-posts
包简介
Query and display posts in WordPress
关键字:
README 文档
README
Query and display posts in WordPress.
Installation
Install via composer:
composer require grottopress/wordpress-posts
Usage
<?php declare (strict_types = 1); use GrottoPress\WordPress\Posts; // Instantiate Posts $posts = new Posts([ 'image' => [ 'size' => 'some-size', //could be array (eg: array(150,150)) or string (eg: 'post-thubnail') 'margin' => '0 10px 0 0', ], 'excerpt' => [ 'length' => 30, // number of words. use -1 for all 'after' => [ 'types' => ['category', 'post_tag'] ] ], 'title' => [ 'position' => 'top' // either 'top' or 'side' of image 'tag' => 'h1', // 'h2' by default, 'before' => [ 'types' => ['share_link', 'tweet_link'], ], 'after' => [ 'types' => ['author_name', 'published_date', 'comments_link'], ] ], 'wp_query' => [ // WP_Query args // See https://codex.wordpress.org/Class_Reference/WP_Query ] ]); // Display posts echo $posts->render();
You may use the styles defined in dist/css in your theme (or plugin):
\add_action('wp_enqueue_scripts', function () { $css = \is_rtl() ? 'posts-rtl.css' : 'posts.css'; \wp_enqueue_style( 'wordpress-posts', \get_stylesheet_directory_uri()."/vendor/grottopress/wordpress-posts/dist/css/$css" ); });
Arguments
Full list of arguments, with their defaults, are as follows:
$args = [ 'class' => 'small', // Wrapper HTML classes 'tag' => 'div', // Wrapper HTML tag. Use 'ul' for list posts. 'layout' => 'stack', // 'stack' or 'grid' 'text_offset' => 0, // Distance from image side to text (title, excerpt) 'related_to' => 0, // Post ID. Use this for related posts 'image' => [ 'size' => '', 'align' => '', // 'left', 'right' or 'none' 'margin' => '', 'link' => true, ], 'excerpt' => [ 'length' => 0, // Number of words. Use -1 for full excerpt, -2 for full content 'paginate' => 1, // If showing full content, whether or not to paginate. 'more_text' => \esc_html__('read more'), 'after' => [ 'types' => [], // Info to display after content/excerpt 'separator' => '|', 'before' => '<small class="entry-meta after-content">', 'after' => '</small>', ], ], 'title' => [ 'tag' => 'h2', 'position' => '', // Relative to image: 'top' or 'side' 'length' => -1, // Number of words. Use -1 for full length 'link' => true, 'before' => [ 'types' => [], // Info to display before title 'separator' => '|', 'before' => '<small class="entry-meta before-title">', 'after' => '</small>', ], 'after' => [ 'types' => [], // Info to display after title 'separator' => '|', 'before' => '<small class="entry-meta after-title">', 'after' => '</small>', ], ], 'pagination' => [ 'position' => [], // 'top' and/or 'bottom' 'key' => '', // URL query key to use for pagination. Defaults to 'pag'. 'mid_size' => null, 'end_size' => null, 'prev_text' => \esc_html__('← Previous'), 'next_text' => \esc_html__('Next →'), ], 'wp_query' => [ // WP_Query args // See https://codex.wordpress.org/Class_Reference/WP_Query ] ]
Posts info
The following are possible values you may supply to $args['title']['before']['types'], $args['title']['after']['types'] and $args['excerpt']['after']['types']:
avatar__<size>eg:avatar__40updated_ago,updated_ago__actual,updated_ago__differencepublished_ago,published_ago__actual,published_ago__differenceauthor_namecomments_linkupdated_dateupdated_timepublished_datepublished_timecategory_listorcategorytag_listorpost_tagedit_linkdelete_linktweet_buttonsharethis_buttonshare_linktweet_linkpin_linklinkedin_linkbuffer_linkdigg_linktumblr_linkreddit_linkblogger_linkpocket_linkskype_linkviber_linkwhatsapp_linktelegram_linkvk_link- The name of a filter hook. A function should then be defined and added to that filter. Function args:
string $output, int $post_id, string $separator. - A post meta key. This would display a single meta value for that key.
- A taxonomy name. This would display a list of all terms of that taxonomy the post was assigned to.
Social media icons
If you would like to show icons for social links, you need to install font awesome v5.
Development
Run tests with composer run test.
Contributing
- Fork it
- Switch to the
masterbranch:git checkout master - Create your feature branch:
git checkout -b my-new-feature - Make your changes, updating changelog and documentation as appropriate.
- Commit your changes:
git commit - Push to the branch:
git push origin my-new-feature - Submit a new Pull Request against the
GrottoPress:masterbranch.
grottopress/wordpress-posts 适用场景与选型建议
grottopress/wordpress-posts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.21k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 grottopress/wordpress-posts 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 grottopress/wordpress-posts 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 grottopress/wordpress-posts 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Must-use plugin integrating WordPress with the Upsun platform: environment awareness, router-cache friendliness, safe preview clones, deploy migrations, Site Health checks, and a wp upsun CLI command.
Inertia.js server-side adapter for PHP. Handles full visits, Inertia XHR visits, asset-version 409 handshakes and partial reloads. Framework-agnostic, with transparent WordPress integration.
Adds Cache-Tag HTTP response headers for singular WordPress content and purges Cloudflare by tag when content changes.
AI Chatbot & Helpdesk Agent for WooCommerce. Connects your store to Egentify for AI-powered chat, order tracking, email, and ticketing.
MIDDAG's reference architecture for a WordPress plugin — composes the OSS framework/wordpress/ui libraries end to end.
Assets helper package for the Hybrid Core framework.
统计信息
- 总下载量: 1.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-01