最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

templates - Two different single.php depending on source page

programmeradmin1浏览0评论

I wonder if I can have two single.php templates for different sources.

The problem is:

- I have the full website, with the blog and the home.php that opens posts in the single.php template.

- Then, I have to create a different home.php (without header and footer) to show in a webview inside a mobile app, therefore, I need that the posts should open on a different single.php template, also without header and footer, alongside other features not available on the app version.

The site is responsive, so wp_is_mobile is not an option.

How can I do that?

I wonder if I can have two single.php templates for different sources.

The problem is:

- I have the full website, with the blog and the home.php that opens posts in the single.php template.

- Then, I have to create a different home.php (without header and footer) to show in a webview inside a mobile app, therefore, I need that the posts should open on a different single.php template, also without header and footer, alongside other features not available on the app version.

The site is responsive, so wp_is_mobile is not an option.

How can I do that?

Share Improve this question edited Apr 26, 2020 at 15:50 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Apr 26, 2020 at 0:00 rayagorayago 1 2
  • Post your single.php contents and I'll see what I can do for you. :) Pretty sure you can just use the same single.php with some conditional wrapping. – Joel Hager Commented Apr 26, 2020 at 2:11
  • Are you able to pass some sort of variable or indicator from the app? This is actually a relatively simple process if we have something we can 'check for'. Even something as simple as the app being classed as a specific type of browser - we're already able to check if a site is on Safari, Chrome, Firefox, IE/Edge, Opera, etc. I regularly do this if I need to have different CSS depending on the browser - so I just chuck the browser identifier into the body tag as a class and write CSS based on that. – Tony Djukic Commented Apr 26, 2020 at 17:00
Add a comment  | 

1 Answer 1

Reset to default 0

You would use page templates to accomplish what you're doing. If you specify a page-{slug}.php, it'll use that one instead. It always does upward traversal. So if there's a specific page, it'll use it. If not, it'll be one level more general.

Copy the home.php PHP into your new one, and remove the calls for the header and footer. Voila!

You could also wrap the calls to the header/footer in an is_page() conditional

if (is_page("slug-name") { get_header() } <- pseudo code for you to get the idea You'll have to see what all you need to wrap in conditionals for your use case.

More info on using Page Templates: here

发布评论

评论列表(0)

  1. 暂无评论