admin管理员组文章数量:1128488
I am trying to create a single.php file to be the default template for displaying single posts in a child theme that I have created from the TwentyTwentyThree theme. The reason I want to set this as the default is I have a lot of custom css used for the navbar that is a real pain to get working with the new editor, so I just want to have the single.php file that I can use to display the content as default. The code required is rendered in my header.php file and works well for the page templates, like front-page.php or other custom templates which I have created and is working fine Is there a way to do this?
I know that the block themes work a little differently but I thought that the hierarchy would still apply and I like the other features of the theme so I would like to keep it.
Here is the code for the single.php file:
<?php
get_header();
?>
<article class='content px-3 py-5 p-md-5'>
<?php
if( have_posts() ){
while(have_posts()){
the_post();
the_content();
}
}
?>
</article>
<?php
get_footer();
?>
I am trying to create a single.php file to be the default template for displaying single posts in a child theme that I have created from the TwentyTwentyThree theme. The reason I want to set this as the default is I have a lot of custom css used for the navbar that is a real pain to get working with the new editor, so I just want to have the single.php file that I can use to display the content as default. The code required is rendered in my header.php file and works well for the page templates, like front-page.php or other custom templates which I have created and is working fine Is there a way to do this?
I know that the block themes work a little differently but I thought that the hierarchy would still apply and I like the other features of the theme so I would like to keep it.
Here is the code for the single.php file:
<?php
get_header();
?>
<article class='content px-3 py-5 p-md-5'>
<?php
if( have_posts() ){
while(have_posts()){
the_post();
the_content();
}
}
?>
</article>
<?php
get_footer();
?>
Share
Improve this question
asked Jan 3, 2024 at 7:22
ShanahandoShanahando
31 bronze badge
3
|
1 Answer
Reset to default 0The answer is, AFAIK, that you shouldn't. It goes against how block themes work. Rather you should try to get your css to work with the block theme. What are the issues with getting your CSS to work with the new editor?
You can add it as style.css in your child theme, or you can add custom block styles with a simple plugin. The later is my prefered method as it works quite well with the block editor, and as a plugin it can be used even if I switch themes.
版权声明:本文标题:How do I create a single.php file as the default template for single posts in the twentytwentythree theme? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736701608a1948453.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.html
template files and block templates. I'd recommend you work entirely within the site editor for as much as possible, you can always enqueue additional CSS/JS, as well as add classes to blocks to apply that CSS. Putting CSS in aheader.php
is bad practice even when using PHP templates – Tom J Nowell ♦ Commented Jan 3, 2024 at 9:23theme.json
, not with new CSS. At all costs avoid inline CSS be that when you write it in the UI or insert it into files in the theme manually, that's true of both block themes and classic themes. As far as block themes are concerned the pain usually occurs because it's difficult to do something you don't need to do or shouldn't be doing. E.g. don't try to write CSS to adjust margins and paddings on the header, use the block editor controls – Tom J Nowell ♦ Commented Jan 4, 2024 at 9:31