网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

wordpress - 获取分配给模板的帖子

GG网络技术分享 2025-03-18 16:12 7


问题描述:

I want to get the post that is assigned to this template and display the content,

currently, I can only display the post content if I put the post id manually. I only want to display the content if the post is assigned to this template and display the content inside woocommerce page

<?php

/**

* Template Name: Sign up Page

*

* @package WordPress

* @subpackage Twenty_Fourteen

* @since Twenty Fourteen 1.0

*/

echo \'this is the signup page\';

$post = get_post(2);

$output = apply_filters( \'the_content\', $post->post_content );

echo $output;

图片转代码服务由CSDN问答提供

感谢您的意见,我们尽快改进~

功能建议

我想获取分配给此模板的帖子并显示内容,目前,我只能显示 如果我手动输入帖子ID,则发布内容。 我只想显示内容,如果帖子被分配到此模板并在woocommerce页面内显示内容</ p>

 &lt;?php 

/ **

*模板名称 :注册页面

*

* @package WordPress

* @subpackage Twenty_Fourteen

* @since Twenty Fourteen 1.0

* /

echo\'这是注册页面\';

$ post = get_post(2);

$ output = apply_filters(\'the_content\',$ post-&gt; post_content);

echo $ output;

</ code> </ pre>

</ div>

网友观点:

Updated:

You could try to use get_page_template_slug() function to check, if the current page uses specific template, something like:

  while ( have_posts() ) : the_post();

$current_template = get_page_template_slug( get_the_ID() );

if ($current_template == \'signup.php\' ) {

the_content();

}

endwhile;

标签:

提交需求或反馈

Demand feedback