Forums

Strange multiple <br /> in the_content() when called on homepage-sidebar (2 posts)

  1. Llasse
    Member
    Posted 2 years ago #

    I have a really strange problem:
    I use the following code in my sidebar to get a specific aside for a couple of categories:

    <div id="randnotiz">
    			<?php  if(is_page(13) OR is_page(171) OR is_page(178) OR is_category(6)) { $rn = 'randnotiz_erste'; /* Erste */ } elseif(is_page(34) OR is_page(98) OR is_page(164) OR is_category(3)) { $rn = 'randnotiz_zweite'; /* Zweite */ }  elseif(is_page(20) OR is_page(174) OR is_page(176) OR is_category(7)) { $rn = 'randnotiz_ue40'; } else { $rn = 'randnotiz'; }
    			/* MUSS ÜBERARBEITET WERDEN! IRGENDWAS MIT DEN SUBPAGES IN DER ABFRAGE! */
    			echo "$rn funktioniert doch";
    
    	wp_reset_query();
    	$temp = $wp_query;
    	$wp_query = null;
    	$wp_query = new WP_Query();
    	$wp_query->query('category_name='.$rn.'&showposts=1,orderby=date,order=DESC');
    	$temp_posts = $posts;
    	$posts = null;
    	$posts = $wp_query->posts; 
    
    		while (have_posts()) : the_post();
    		the_content();
    		endwhile;  ?>
      		</div>

    Two problems:

    1. This works for the categories "Erste" and "Ü40", but for my "Zweite" category, it fails to realize that it is on the page 34 (even though this is 100% correct!) so it shows the aside, that is supposed to show, if there is no category asigned (such as my "homepage" index.php).

    2. On my index.php it adds 8 <br /> tags after the correctly displayed paragraph. It doesn't do that on any other page.. why does it do that?

    I'm glad for any brainstorming or help I can receive, it really doesn't make any sense to me..

    Problem can be seen under: http://thc.franziskaner-fc.de/wordpress/

  2. Llasse
    Member
    Posted 2 years ago #

    It seems as if for every post that is added, the_content(); produces an extra <br /> as my new wp_query (with showposts=1) only returns one post , but TheLoop still processes all the posts there are, and displays a <br /> for each "empty post" (as it only got one from wp_query();)

    Understanding this still doesn't help me find a senseble solution. I used this workaround, as the site has to go online this weekend (but I'd be glad to get some help!)

    while (have_posts()) : the_post();
    $content = get_the_content();
    str_replace("<br />","",$content);
    echo $content;
    		endwhile;

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.