0

現在、カスタムの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(); ?>
4

1 に答える 1

1

これは、コード構文が正しいため、プラグインが実際に何をしているかに大きく依存します。

Multiple Content Blocksプラグインを使用していて、最新の Wordpress バージョン 3.5.1 を使用している場合、プラグインに互換性がない可能性があります。これはあなたの問題である可能性があるため、Wordpress インストールに対するプラグインのバージョンの互換性を確認します。

編集:

プラグインは関数 the_content() にフィルターを適用することで機能するため、the_content() 関数が呼び出される前に the_block() を宣言することによってのみ機能します。

解決策は、例として、出力 the_block() をキャプチャし、後でそれを印刷することです。

<?php 
    ob_start();  
    the_block('Latest Products'); 
    $latest_products_contents = ob_get_contents(); 
    ob_end_clean();
?>
<!-- Further down.. -->
<?php echo $latest_products_contents; ?>
于 2013-03-10T23:46:43.293 に答える