1

私は本当に次のような手をいただければ幸いです。

  • を使用して投稿を表示するWordpressページがありますquery_posts('cat=10&tag=parties&orderby=rand');

  • 私がやりたいのは、リストを半分に分割し、中央にテキストを挿入することです。理想的には、テキストはWordpressのページのWYSIWYGエディターから取得されます。最初の投稿を除いた2番目のクエリで2セットの「phpクエリ投稿」が必要だと思いますか?

誰かが助けることができますか?

どうもありがとう!

4

1 に答える 1

1

使用する代わりに、query_postsなぜ使用しないのですWP_Queryか?これにより、サイズを照会できる配列が取得されます。次に、増分するカウンターを作成し、中間点に到達したら、必要なものを挿入して次に進みます。

次のように設定します。

// first, run the main loop to get the text editor content
while(have_posts()) : the_post(); 
  // we just assign it to a variable at this point without printing it
  $content_to_insert = get_the_content(); 
endwhile;

// now we set up the query to get out all the party posts
$parties_query = array( 
  'cat' => 10, 
  'tag' => 'parties', 
  'orderby' => 'rand', 
  'posts_per_page' => -1 
);

// NB. you will not get ALL your results unless you use 'posts_per_page' or 'showposts' set to -1

// Now run a new WP_Query with that query
$parties = new WP_Query($parties_query);

// get the halfway point - needs to be a whole number of course!
$half = round( sizeof($parties)/2 );

// this is our counter, initially zero
$i = 0

while($parties->have_posts()) : $parties->the_post(); ?>

<?php if ($i == $half) : ?>

// we are halfway through - print the text!
<?php echo apply_filters('the_content', $content_to_insert); ?>

<?php else : ?>

// render your party stuff
// you can use tags reserved for use in the loop, eg.

<div class="party">
  <h2><?php the_title(); ?></h2>
</div>

<?php endif; ?>

<?php $i++; endwhile; ?>

それがうまくいくことを願っています。昨夜はクリスマスパーティーの深夜でした。

于 2012-12-22T11:20:52.377 に答える