grottopress / wordpress-posts
查询并显示WordPress中的帖子
v1.0.0
2023-05-31 18:05 UTC
Requires
- php: >=7.0
- grottopress/getter: ^1.0
Requires (Dev)
- codeception/codeception: ^4.1
- codeception/module-asserts: ^1.3
- lucatume/function-mocker: ^1.3
- wp-cli/wp-cli-bundle: ^2.1
- dev-master
- v1.0.0
- v0.17.3
- v0.17.2
- v0.17.1
- v0.17.0
- v0.16.5
- v0.16.4
- v0.16.3
- v0.16.2
- v0.16.1
- v0.16.0
- v0.15.1
- v0.15.0
- 0.14.1
- 0.14.0
- 0.13.0
- 0.12.2
- 0.12.1
- 0.12.0
- 0.11.1
- 0.11.0
- 0.10.3
- 0.10.2
- 0.10.1
- 0.10.0
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.0
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.2
- 0.1.1
- 0.1.0
This package is auto-updated.
Last update: 2024-09-23 15:10:33 UTC
README
查询并显示WordPress中的帖子。
安装
通过composer安装
composer require grottopress/wordpress-posts
使用
<?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();
您可以在您的主题(或插件)中使用 dist/css 中定义的样式
\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" ); });
参数
以下为参数的完整列表,包括它们的默认值:
$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 ] ]
帖子信息
以下为可以提供给 $args['title']['before']['types']、$args['title']['after']['types'] 和 $args['excerpt']['after']['types'] 的可能值
avatar__<size>例如:avatar__40updated_ago、updated_ago__actual、updated_ago__differencepublished_ago、published_ago__actual、published_ago__difference作者名称评论链接更新日期更新时间发布日期发布时间category_list或categorytag_list或post_tag编辑链接删除链接推文按钮分享此按钮分享链接推文链接推送链接领英链接buffer链接digg链接tumblr链接reddit链接blogger链接pocket链接skype链接viber链接whatsapp链接telegram链接vk链接- 一个过滤钩子名称。然后应该定义并添加到该过滤器中。函数参数:
string $output, int $post_id, string $separator。 - 一个帖子元数据键。这将显示该键的单个元数据值。
- 一个分类名称。这将显示帖子所属的分类的所有术语列表。
社交媒体图标
如果您想显示社交媒体链接的图标,您需要安装 font awesome v5。
开发
使用 composer run test 运行测试。
贡献
- 分支它
- 切换到
master分支:git checkout master - 创建您的功能分支:
git checkout -b my-new-feature - 进行更改,根据需要更新更改日志和文档。
- 提交更改:
git commit - 推送到分支:
git push origin my-new-feature - 向
GrottoPress:master分支提交新的 Pull Request。