下面是我的html代码,其中有两个不同的部分,我无法在wordpress中使它们动态化。
<section class="contact">
<h1>how it works</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Omnis, molestias facere nam esse voluptatum cupiditate recusandae deleniti neque quidem! Expedita necessitatibus saepe tempore corporis magnam ut impedit ea tempora quae.Select the products you wish to order. request a quote, fill out all the required fields and upload your artwork. Zazzoo will be in contact with you withing 24 hours to confirm your order.</p>
<div class="button">
<button type="button" class="btn btn-default">Contact us</button>
</div>
</section><!-- end of contact section -->
<section class="opportunity">
<div class="row">
<div class="col-lg-8 col-md-8 ideas">
<h2>turn your ideas into reality</h2>
<hr/><p>weretrerum dolor sit amet, consectetur adipisicing elit. Dolor laudantium porro natus quo, sit ex nemo, nostrum pariatur ipsum, hic, officiis facilis enim debitis? Doloremque sequi sed ex quae, eaque.</p>
</div>
<div class="col-lg-4 col-md-4 opportunitycolumn">
<h2>opportunity</h2>
<hr>
<br/>
<h3>Are you a designer?</h3>
<p>Send us your work and we will manage your print...</p>
</div>
</div>
</section>
如何将上面的代码转换为wordpress,以便它变得动态?
答案 0 :(得分:0)
以下是WordPress中基本循环的示例,该循环从类别中选择最新文章:
<?php $get_posts = new WP_Query( array( 'cat' => 21 ) ); // "'cat' => 21" replace with whichever category your post is in
while($get_posts->have_posts()) : $get_posts->the_post(); ?>
<section class="contact">
<div>
<?php The_post_thumbnail('full'); ?>
<div>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
</div>
</section>
<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>
<?php The_post_thumbnail('full'); ?>
在您的情况下不需要,但这也是特色图片的设置。
你可以用循环做很多事情来按照你需要的方式进行自定义
Here是一个关于循环的更深入的参考。
如果您不想将帖子放在某个类别中,您也可以通过以下内容(未经测试)Reference
专门通过其ID来调用它<?php
$post_id = 1; //changeme
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
echo $title;
echo $queried_post->post_content;
?>