尝试使用WP\\u查询在侧栏中放置一组循环。
<div id="FL-pest-libray-sidebar">
<?php $category_query_string = new WP_Query(array( \'post_type\' => \'page\' , \'posts_per_page\' => \'-1\' , \'post_parent\' => \'413\')); if ( have_posts() ) : while ( $category_query_string->have_posts() ) : $category_query_string->the_post(); ?>
<div <?php
$catspacetitle = get_the_title();
$cattitle = str_replace(" ", "-", $catspacetitle);
echo \'id="\',$cattitle,\'"\'
?> class="FL-pest-cat">
<p <?php
$pcatspacetitle = get_the_title();
$pcattitle = str_replace(" ", "-", $pcatspacetitle);
echo \'id="\',$pcattitle,\'-title"\'
?>class="FL-pest-cat-title"><a href="#"><strong>
<?php the_title(); ?>
</strong></a></p>
<?php
$postid = get_the_ID();
if ($postid == \'654\') {
$curretnCat = \'11\';}
elseif ($postid == \'661\') {
$curretnCat = \'12\';}
elseif ($postid == \'662\') {
$curretnCat = \'13\';}
elseif ($postid == \'664\') {
$curretnCat = \'15\';}
elseif ($postid == \'665\') {
$curretnCat = \'16\';}
elseif ($postid == \'666\') {
$curretnCat = \'17\';}
elseif ($postid == \'668\') {
$curretnCat = \'18\';}
elseif ($postid == \'669\') {
$curretnCat = \'19\';}
elseif ($postid == \'670\') {
$curretnCat = \'20\';}
elseif ($postid == \'671\') {
$curretnCat = \'21\';}
elseif ($postid == \'673\') {
$curretnCat = \'22\';}
elseif ($postid == \'674\') {
$curretnCat = \'23\';}
echo \'<div id="pests-cat-\',$curretnCat,\'"class="FL-pest-indv">\';
echo \'<ul>\';
$query_string = new WP_Query(array( \'post_type\' => \'Pests\', \'posts_per_page\' => \'-1\' , \'cat\' => $curretnCat )); if ( have_posts() ) : while ( $query_string->have_posts() ) : $query_string->the_post(); ?>
<li>
<p <?php
$pestspacetitle = get_the_title();
$pesttitlesearch = array(\' \', \'(\', \')\', \'.\');
$pesttitlereplace = array(\'-\', \'\', \'\',\'\');
$pesttitle = str_replace($pesttitlesearch, $pesttitlereplace, $pestspacetitle);
echo \'id="\',$pesttitle,\'"\'
?>class="FL-pest-indv-title"><a href="<?php the_permalink(); ?>"><strong>
<?php the_title(); ?>
</strong></a></p>
</li>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
</ul>
</div> </div>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
</div>
它最终只会破坏页面,但它本身可以作为页面模板工作。
SO网友:eteich
由于侧栏是在循环内部部署的,因此
if ( have_posts() ) :
是什么导致它断裂的。修复方法如下:
<div id="FL-pest-libray-sidebar">
<?php $category_query_string = new WP_Query(array( \'post_type\' => \'page\' , \'posts_per_page\' => \'-1\' , \'post_parent\' => \'413\')); while ( $category_query_string->have_posts() ) : $category_query_string->the_post(); ?>
<div <?php
$catspacetitle = get_the_title();
$cattitle = str_replace(" ", "-", $catspacetitle);
echo \'id="\',$cattitle,\'"\'
?> class="FL-pest-cat">
<p <?php
$pcatspacetitle = get_the_title();
$pcattitle = str_replace(" ", "-", $pcatspacetitle);
echo \'id="\',$pcattitle,\'-title"\'
?>class="FL-pest-cat-title"><a href="#"><strong>
<?php the_title(); ?>
</strong></a></p>
<?php
$postid = get_the_ID();
if ($postid == \'654\') {
$curretnCat = \'11\';}
elseif ($postid == \'661\') {
$curretnCat = \'12\';}
elseif ($postid == \'662\') {
$curretnCat = \'13\';}
elseif ($postid == \'664\') {
$curretnCat = \'15\';}
elseif ($postid == \'665\') {
$curretnCat = \'16\';}
elseif ($postid == \'666\') {
$curretnCat = \'17\';}
elseif ($postid == \'668\') {
$curretnCat = \'18\';}
elseif ($postid == \'669\') {
$curretnCat = \'19\';}
elseif ($postid == \'670\') {
$curretnCat = \'20\';}
elseif ($postid == \'671\') {
$curretnCat = \'21\';}
elseif ($postid == \'673\') {
$curretnCat = \'22\';}
elseif ($postid == \'674\') {
$curretnCat = \'23\';}
echo \'<div id="pests-cat-\',$curretnCat,\'"class="FL-pest-indv">\';
$query_string = new WP_Query(array( \'post_type\' => \'Pests\', \'posts_per_page\' => \'-1\' , \'cat\' => $curretnCat )); while ( $query_string->have_posts() ) : $query_string->the_post(); ?>
<p <?php
$pestspacetitle = get_the_title();
$pesttitlesearch = array(\' \', \'(\', \')\', \'.\');
$pesttitlereplace = array(\'-\', \'\', \'\',\'\');
$pesttitle = str_replace($pesttitlesearch, $pesttitlereplace, $pestspacetitle);
echo \'id="\',$pesttitle,\'"\'
?>class="FL-pest-indv-title"><a href="<?php the_permalink(); ?>"><strong>
<?php the_title(); ?>
</strong></a></p>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>