admin管理员组文章数量:1389807
the original .php part of my theme looks like this:
$bam_related_posts_taxonomy = get_theme_mod( 'bam_related_posts_taxonomy', 'category' );
$bam_post_args = array(
'posts_per_page' => absint( get_theme_mod( 'bam_related_posts_count', '3' ) ),
'orderby' => 'rand',
'post__not_in' => array( get_the_ID() ),
);
(*A lot of other codes here*)
wp_reset_postdata();
I added this part below the 'post___not_in' myself:
'category__not_in' => array(21),
This way, I exclude a certain category. It's working, however, I want to add this last part of the code in my own plugin, so it won't reset when I update my theme. How do I get this last line into the functions.php of my own plugin? Simply adding that line to it won't work, it needs to point to the rest of the code...
the original .php part of my theme looks like this:
$bam_related_posts_taxonomy = get_theme_mod( 'bam_related_posts_taxonomy', 'category' );
$bam_post_args = array(
'posts_per_page' => absint( get_theme_mod( 'bam_related_posts_count', '3' ) ),
'orderby' => 'rand',
'post__not_in' => array( get_the_ID() ),
);
(*A lot of other codes here*)
wp_reset_postdata();
I added this part below the 'post___not_in' myself:
'category__not_in' => array(21),
This way, I exclude a certain category. It's working, however, I want to add this last part of the code in my own plugin, so it won't reset when I update my theme. How do I get this last line into the functions.php of my own plugin? Simply adding that line to it won't work, it needs to point to the rest of the code...
Share Improve this question asked Mar 14, 2020 at 15:30 IzzyIzzy 1 2 |1 Answer
Reset to default 0You don't, what you've modified is a template file, those don't go in plugins.
Instead, create a child theme and copy this file into that theme. WordPress will preferentially load templates from the child theme, falling back to the original parent theme. This way any modifications you make in the child theme will overwrite the parent, and if the parent is updated no changes are lost
本文标签: How to get this php code from my theme into my plugin
版权声明:本文标题:How to get this .php code from my theme into my plugin? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744668716a2618692.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
__not_in
type parameters are extremely expensive/slow those queries are very heavy on the server – Tom J Nowell ♦ Commented Mar 14, 2020 at 15:49