wordpress的自定义主题新页面
问题描述:
我为wordpress创建了一个自定义主题。当我说'添加新的'页面,我把内容放入这个页面时,它只显示页脚和页眉,但是dosnt钩住了我在该页面的CMS中的内容。wordpress的自定义主题新页面
这是我有:page.php文件
<?php get_header(); ?>
<div class="row">
<div class="col-sm-12">
<?php
if (have_posts()) : while (have_posts()) : the_post();
get_template_part('content', get_post_format());
endwhile; endif;
?>
</div> <!-- /.col -->
</div> <!-- /.row -->
<?php get_footer(); ?>
它是一个漫长的一天我错了在这里做什么。请提供任何提示?
还想从这个新页面中制作一个父页面,但其唯一的选项与页面属性是'默认模板'。
答
我的实际问题,已解决。所以我为我的WordPress使用了“高级自定义字段”插件。使用这个问题的问题是,它仍然需要你做一些编码。
我添加了一个新页面。
对于那个页面我有一个标题图像和内容。所以对于ACF(高级自定义字段)等于两个字段类型“图像 - >字段类型和文本区域 - >字段类型”
字段名称是我用来调用字段到我的.php页面模板。
字段名称:图片=头图像
字段名称:(2)文本区=头图像文本顶部(和)头图像-文本作者
(我需要在图像上显示我的文字,这就是为什么我的div只是基于标题图像。)
所以我迷上了我的页面模板,然后添加了我想在此页面模板上显示的字段的钩子。
页stay.php:
<?php
/*Template Name: Stay - Parent Page */
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while (have_posts()) : the_post(); ?>
<article id="post=<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- <header class="entry-header">
<?php the_title('<h1 class="entry-title">', '</h1>'); ?>
</header>(you can use this if you need your page header to display)-->
<div class="enry-content">
<?php
$image = get_field('header-image');
if(!empty($image)): ?>
<div class="head-image">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<div class="head-text-box">
<div class="head-text-box-holder">
<p class="headtext-quote"><?php the_field('header-image-text-top'); ?></p>
<p class="headtext-author"><?php the_field('header-image-text-bottom'); ?></p>
</div>
</div>
</div>
<?php endif; ?>
</article>
<?php endwhile; ?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_footer(); ?>
答
如果您没有模板部件,请使用the_content()而不是 get_template_part('content',get_post_format());
好吧,你只加载模板的一部分,这你还没有使用共享。该模板部分的内容是什么?此外,我认为你误解了[get_post_format](https://codex.wordpress.org/Function_Reference/get_post_format)的作用 - 这不是正确的功能 - 可能你想[get_post_type](https://developer.wordpress.org/reference/functions/get_post_type /),这会导致一个模板名称为“content-page.php” –