現在、カスタムのWordpressテーマを開発しようとしています。ホームページに、2つ目のコンテンツブロックを追加する必要があります。私はこれを行うためにプラグインを使用しています。これを行うには、コンテンツブロックを配置する場所に次を追加するだけです。
<?php the_block('Latest Products')?>
ただし、これを追加しても、phpのフォーマットが原因であると私が信じている効果はないようです。私はphpにかなり慣れていないので、どんな助けでも大歓迎です。
私のコードは次のとおりです-HTMLの大部分を切り取りました。それはその「endforeach」タグと関係があると思いますか?
<?php get_header(); ?>
<?php if(have_posts()) :?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php
global $post;
$myposts = get_posts('numberposts=4&category=1');
foreach($myposts as $post) :
?>
<div class="blogsnippet">
<div class="postdate">
<span class="top"><?php the_time ('j')?></span><br/><span class="bottom"><?php the_time('M');?></span>
</div>
<div class="postexcerpt">
<h3><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h3>
<p><?php echo(get_the_excerpt());?></p>
</div>
</div>
<?php endforeach;?>
<?php the_block('Latest Products')?>
<?php endwhile; endif; ?>
<?php get_footer(); ?>
編集
さて、どうやらそれはループの外に置く必要がありますが、それでも機能しません。何か案は?
<?php get_header(); ?>
<?php if(have_posts()) :?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php
global $post;
$myposts = get_posts('numberposts=4&category=1');
foreach($myposts as $post) :
?>
<div class="blogsnippet">
<div class="postdate">
<span class="top"><?php the_time ('j')?></span><br/><span class="bottom"><?php the_time('M');?></span>
</div>
<div class="postexcerpt">
<h3><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h3>
<p><?php echo(get_the_excerpt());?></p>
</div>
</div>
<?php endforeach;?>
<?php endwhile; endif; ?>
<?php the_block('Latest Products')?>
<?php get_footer(); ?>