admin管理员组文章数量:1203973
Exploring WordPress and bumped into this issue: In my theme root page-templates/home.php
which is a common page template used in multiple pages. Now I want to include the same template (with some minor query parameters changed) in my archive/category page. I know I can just copy and paste the whole home.php template to a category.php. But It feels like there is a better way to do it.
[my home page showing the latest article at the top, 3 popular articles (by view count) in right side and at the bottom all the recent articles]
So my question is how can use the same template as the home and other pages in the category pages without code duplication??
The only code difference between home and category template is at the top of the category.php
$archive_category = get_queried_object();
$popular_posts = new WP_Query(
array(
'cat' => $archive_category->cat_ID, /* home page doesn't have this parameter (only difference) */
'meta_key' => 'wpb_post_views_count',
'posts_per_page' => _POPULAR_POST_LIMIT,
'orderby' => array(
'meta_value_num' => 'DESC',
'date' => 'DESC'
)
)
);
本文标签: customizationMake the home page template my archivecategory page template without code duplication
版权声明:本文标题:customization - Make the home page template my archivecategory page template without code duplication 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738666549a2105737.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论