webForumDet fria alternativet

En extra img-fil i koden, kan inte hitta den

PHP

15 svar · 1 985 visningar · startad av magnusfeldth

Medlem sedan jan. 20034 480 inlägg
Frågan#1

Genom ett gratis tema-script har jag en wordpress-sida, men det är nåt som är fel i själva koden för att visa enskild sida. Där bilden skall in lägger den till en extra img-skrivning.

så här ser koden ut:

<?php get_header(); ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div class="eachpost heading1">
	<div>
		<?php the_title(); ?>
	</div>
</div>	

	<?php 
		$content = get_the_content($more_link_text, $stripteaser, $more_file);
		$content = apply_filters('the_content', $content);
		$content = preg_replace('/<img[^>]+./','', $content);
		$content = str_replace('<p>','',$content);
		$content = str_replace('</p>','<br /><br />',$content);		
		$content = str_replace('<div class="eachpost "><div></div></div>','',$content);
		$content = str_replace('<div class="eachpost twocols"><div></div></div>','',$content);
		$content = str_replace('<div class="eachpost threecols"><div></div></div>','',$content);
		$content = str_replace(']]>', ']]&gt;', $content);
	?>
	<div class="eachpost twocols">
		<div>
			<?php echo $content; ?>
		</div>
	</div>

<div class="main">
	<?php 
		$imgcontent = get_the_content($more_link_text, $stripteaser, $more_file);
		$imgcontent = apply_filters('the_content', $imgcontent);
		$imgcontent = preg_replace('/<p[^>]+./','', $imgcontent);
		$imgcontent = str_replace('<p>','',$imgcontent);
		$imgcontent = str_replace('</p>','',$imgcontent);

		if ( strstr($imgcontent,'<div class="eachpost')) {
			echo $imgcontent; 
		} else {
		
			// gallery not found;
			
			$images = explode("<img ", $imgcontent);			
			if (count($images) != "1") {			
			for ($i=0;$i<count($images);$i++) {
			
				if ($images[$i] != "") {
					$image = str_replace('<img ','<div class="eachpost "><div><img ','<img '.$images[$i]);
					$imagepieces = explode("/>", $image);
					$imageurl = substr($imagepieces[0], 0, -2) . '" /></div></div>';
					
					$imagesrc_temp = explode('src="', $imageurl);
					$imagesrc = explode('"', $imagesrc_temp[1]); // get src
					
					$imagew_temp = explode('width="', $imageurl);
					$imagew = explode('"', $imagew_temp[1]); // get width
					
					$imageh_temp = explode('height="', $imageurl);
					$imageh = explode('"', $imageh_temp[1]); // get height
				
					$upload_path = get_option( 'upload_path' );
					$upload_path = trim($upload_path);
					$img_full_url = $imagesrc[0];

					$temp = substr(strrchr($upload_path, "/"), 1);
			
					list($url, $filename) = explode($temp, $img_full_url);
			
					$img_url = $upload_path . "/" . $filename;
			
					$imagesize = getimagesize($img_url);
					list($width, $height, $type, $attr) = getimagesize($img_url);
					$theClass = "eachpost ";
					if ( $width < "440" ) { $new_width = "200"; $theClass = "eachpost "; } 
						else if ( $width < "660" ) { $new_width = "430"; $theClass = "eachpost twocols"; }
							else { $new_width = "660"; $theClass = "eachpost threecols"; }
			
					$new_height = ($height*$new_width)/$width;

					echo '<div class="'.$theClass.'">
					<div>';
					
					echo '<img src="' . $img_full_url . '" width="' . $new_width . '" height="' . $new_height . '" /></div></div>'; }
		
					
				}
			}
		}	
		?>
</div>

 

<?php endwhile; else: ?>
<div class="warning">
	<p>Sorry, but you are looking for something that isn't here.</p>
</div>
<?php endif; ?>

<div class="navigation_group">
	<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
	<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
</div>

    <?php get_footer(); ?>

Den ger en sida som ser ut som denna - http://www.twocakesandagun.se/?p=1000 - där ser ni alltså att över bilden finns en extra img-fil.

Hilfe!

Medlem sedan feb. 20034 441 inlägg
#2

Det är en tom post ifrån Wordpress som ligger där. Kolla admin så har du säkert en sådan någonstans, i någon kategori. Kollar man källkoden så ser koden exakt likadan ut som bilden på "The thing" som visas, och jag antar att det är en post?

Medlem sedan jan. 20034 480 inlägg
#3

hur menar du, har jag kopierat fel php-kod?

Medlem sedan aug. 20068 090 inlägg
#4

magnusfeldth skrev:

hur menar du, har jag kopierat fel php-kod?

Jag tror han menar att det finns ett inlägg registrerat någonstans i databasen, men där inläggets text och/eller bild inte kommit med i din template (liknande har hänt mig flera ggr).

Alltså, en del av WP tycker att det ska in ett inlägg där, men hittar inte inläggets innehåll.

Så om du letar igenom WP:s admin-gränssnitt så kanske du hittar ett inlägg. Ta bort det.

Nåt sånt....

Medlem sedan jan. 20034 480 inlägg
#5

hm, inte riktigt säker på vad du menar med att jag skall kolla i admin-gränssnittet, skall jag inte leta efter nån särskild kodrad??

Medlem sedan aug. 20068 090 inlägg
#6

magnusfeldth skrev:

hm, inte riktigt säker på vad du menar med att jag skall kolla i admin-gränssnittet, skall jag inte leta efter nån särskild kodrad??

Nä, leta efter ett inlägg som "inte finns". Som verkar kajko.

Eller förresten, sidan har ju id=1000. Finns felet på fler sidor? Kan du hitta själva sidan (sida 1000)? I så fall, kan du radera den och skapa en ny?

Eller, nu vet jag inte om man kan hitta koden till en specifik sida i databasen, men kolla i phpMyAdmin (om du har det?) om du kan. I så fall kanske du kan göra något åt felet där?

Medlem sedan jan. 20034 480 inlägg
#7

Det blir samma på alla sidor. Jämför index-sidan twocakesandagun.se och klicka sen på valfri rubrik för att komma till den individuella sidan - och där får varje sida en extra img-snutt...

har inte PHPMyAdmin, kör allt genom wordpress gränssnittet

Medlem sedan aug. 20068 090 inlägg
#8

magnusfeldth skrev:

Det blir samma på alla sidor. Jämför index-sidan twocakesandagun.se och klicka sen på valfri rubrik för att komma till den individuella sidan - och där får varje sida en extra img-snutt...

har inte PHPMyAdmin, kör allt genom wordpress gränssnittet

Phew.... ja du...

Gör ett sök på följande kod bland templaten:

<div><img src="" width="200" height="" /></div>

Kommentera bort den genom att lägga till:

<!--<div><img src="" width="200" height="" /></div>-->

..och se vad som händer...

Medlem sedan jan. 20034 480 inlägg
#9

jo, jag har sökt efter just den kodsnutten eftersom jag förstår att den är fel, men den hittas inte, antar att den måste genereras av PHP-koden på nåt sätt eftersom den inte syns annars...

Medlem sedan aug. 20068 090 inlägg
#10

magnusfeldth skrev:

jo, jag har sökt efter just den kodsnutten eftersom jag förstår att den är fel, men den hittas inte, antar att den måste genereras av PHP-koden på nåt sätt eftersom den inte syns annars...

Om du sökt på hela snutten ovan och inte hittat något vettigt, så skala bort kod och sök på t.ex.

<img src="" width="200" height="" />

eller t.o.m. bara

width="200"

och se om du får någon träff.

Medlem sedan jan. 20034 480 inlägg
#11

nope, inga träffar. du ser ju koden ovan...

Medlem sedan aug. 20068 090 inlägg
#12

magnusfeldth skrev:

nope, inga träffar. du ser ju koden ovan...

Piss. Tråkigt när man betalar dyra pengar för ett template...eller visst nej. Det var ju gratis. ;)

Seriously, och nu spånar jag bara:

Antagligen finns det en mall för endast sidorna, dvs INTE samma som till förstasidan (eftersom samma fel tydligen inte finns där). Troligen ligger div och/eller img taggen i den mallen och hämtar värdet (width="200" osv) från databasen.

Se om du kan hitta en sån mall. Den KAN heta "page.php", "single.php" eller liknande.

I den mallen (om den finns) kan du ju leta rätt på taggen (div eller img) som då antagligen bör ha en php-kod inuti sig, dvs den kod som hämtar värdet på bl.a. bredden (200) från databasen.

Hittar du nåt, så kommentera bort det du inte vill se med

<!-- koden här -->

och testa i skarpt läge hur sidorna upppför sig.

Funkar det inte, men du hittar sidor som heter page.php och/eller single.php, så posta koden i dom här.

Medlem sedan jan. 20034 480 inlägg
#13

Här är koden för single.php

<?php get_header(); ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div class="eachpost heading1">
	<div>
		<?php the_title(); ?>
	</div>
</div>	

	<?php 
		$content = get_the_content($more_link_text, $stripteaser, $more_file);
		$content = apply_filters('the_content', $content);
		$content = preg_replace('/<img[^>]+./','', $content);
		$content = str_replace('<p>','',$content);
		$content = str_replace('</p>','<br /><br />',$content);		
		$content = str_replace('<div class="eachpost "><div></div></div>','',$content);
		$content = str_replace('<div class="eachpost twocols"><div></div></div>','',$content);
		$content = str_replace('<div class="eachpost threecols"><div></div></div>','',$content);
		$content = str_replace(']]>', ']]&gt;', $content);
	?>
	<div class="eachpost twocols">
		<div>
			<?php echo $content; ?>
		</div>
	</div>

<div class="main">
	<?php 
		$imgcontent = get_the_content($more_link_text, $stripteaser, $more_file);
		$imgcontent = apply_filters('the_content', $imgcontent);
		$imgcontent = preg_replace('/<p[^>]+./','', $imgcontent);
		$imgcontent = str_replace('<p>','',$imgcontent);
		$imgcontent = str_replace('</p>','',$imgcontent);

		if ( strstr($imgcontent,'<div class="eachpost')) {
			echo $imgcontent; 
		} else {
		
			// gallery not found;
			
			$images = explode("<img ", $imgcontent);			
			if (count($images) != "1") {			
			for ($i=0;$i<count($images);$i++) {
			
				if ($images[$i] != "") {
					$image = str_replace('<img ','<div class="eachpost "><div><img ','<img '.$images[$i]);
					$imagepieces = explode("/>", $image);
					$imageurl = substr($imagepieces[0], 0, -2) . '" /></div></div>';
					
					$imagesrc_temp = explode('src="', $imageurl);
					$imagesrc = explode('"', $imagesrc_temp[1]); // get src
					
					$imagew_temp = explode('width="', $imageurl);
					$imagew = explode('"', $imagew_temp[1]); // get width
					
					$imageh_temp = explode('height="', $imageurl);
					$imageh = explode('"', $imageh_temp[1]); // get height
				
					$upload_path = get_option( 'upload_path' );
					$upload_path = trim($upload_path);
					$img_full_url = $imagesrc[0];

					$temp = substr(strrchr($upload_path, "/"), 1);
			
					list($url, $filename) = explode($temp, $img_full_url);
			
					$img_url = $upload_path . "/" . $filename;
			
					$imagesize = getimagesize($img_url);
					list($width, $height, $type, $attr) = getimagesize($img_url);
					$theClass = "eachpost ";
					if ( $width < "440" ) { $new_width = "200"; $theClass = "eachpost "; } 
						else if ( $width < "660" ) { $new_width = "430"; $theClass = "eachpost twocols"; }
							else { $new_width = "660"; $theClass = "eachpost threecols"; }
			
					$new_height = ($height*$new_width)/$width;

					echo '<div class="'.$theClass.'">
					<div>';
					
					echo '<img src="' . $img_full_url . '" width="' . $new_width . '" height="' . $new_height . '" /></div></div>'; }
		
					
				}
			}
		}	
		?>
</div>

 

<?php endwhile; else: ?>
<div class="warning">
	<p>Sorry, but you are looking for something that isn't here.</p>
</div>
<?php endif; ?>

<div class="navigation_group">
	<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
	<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
</div>

    <?php get_footer(); ?>

och koden för page.php

<?php get_header(); ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

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

	<?php 
		$content = get_the_content($more_link_text, $stripteaser, $more_file);
		$content = apply_filters('the_content', $content);
		$content = preg_replace('/<img[^>]+./','', $content);
		$content = str_replace('<p>','',$content);
		$content = str_replace('</p>','<br /><br />',$content);		
		$content = str_replace('<div class="eachpost "><div></div></div>','',$content);
		$content = str_replace('<div class="eachpost twocols"><div></div></div>','',$content);
		$content = str_replace('<div class="eachpost threecols"><div></div></div>','',$content);
		$content = str_replace(']]>', ']]&gt;', $content);
	?>
	<div class="eachpost twocols">
		<div>
			<?php echo $content; ?>
		</div>
	</div>

<div class="main">
	<?php 
		$imgcontent = get_the_content($more_link_text, $stripteaser, $more_file);
		$imgcontent = apply_filters('the_content', $imgcontent);
		$imgcontent = preg_replace('/<p[^>]+./','', $imgcontent);
		$imgcontent = str_replace('<p>','',$imgcontent);
		$imgcontent = str_replace('</p>','',$imgcontent);

		if ( strstr($imgcontent,'<div class="eachpost')) {
			echo $imgcontent; 
		} else {
		
			// gallery not found;
			
			$images = explode("<img ", $imgcontent);			
			if (count($images) != "1") {			
			for ($i=0;$i<count($images);$i++) {
			
				if ($images[$i] != "") {
					$image = str_replace('<img ','<div class="eachpost "><div><img ','<img '.$images[$i]);
					$imagepieces = explode("/>", $image);
					$imageurl = substr($imagepieces[0], 0, -2) . '" /></div></div>';
					
					$imagesrc_temp = explode('src="', $imageurl);
					$imagesrc = explode('"', $imagesrc_temp[1]); // get src
					
					$imagew_temp = explode('width="', $imageurl);
					$imagew = explode('"', $imagew_temp[1]); // get width
					
					$imageh_temp = explode('height="', $imageurl);
					$imageh = explode('"', $imageh_temp[1]); // get height
				
					$upload_path = get_option( 'upload_path' );
					$upload_path = trim($upload_path);
					$img_full_url = $imagesrc[0];

					$temp = substr(strrchr($upload_path, "/"), 1);
			
					list($url, $filename) = explode($temp, $img_full_url);
			
					$img_url = $upload_path . "/" . $filename;
			
					$imagesize = getimagesize($img_url);
					list($width, $height, $type, $attr) = getimagesize($img_url);
					$theClass = "eachpost ";
					if ( $width < "440" ) { $new_width = "200"; $theClass = "eachpost "; } 
						else if ( $width < "660" ) { $new_width = "430"; $theClass = "eachpost twocols"; }
							else { $new_width = "660"; $theClass = "eachpost threecols"; }
			
					$new_height = ($height*$new_width)/$width;

					echo '<div class="'.$theClass.'">
					<div>';
					
					echo '<img src="' . $img_full_url . '" width="' . $new_width . '" height="' . $new_height . '" /></div></div>'; }
		
					
				}
			}
		}	
		?>
</div>

<div class="eachpost twocols">
	<div>
   		<?php if ( comments_open() ) comments_template(); ?>
	</div>
</div>   

<?php endwhile; else: ?>
<div class="warning">
	<p>Sorry, but you are looking for something that isn't here.</p>
</div>
<?php endif; ?>

<div class="navigation_group">
	<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
	<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
</div>

    <?php get_footer(); ?>
Medlem sedan aug. 20068 090 inlägg
#14

Ouch... det här är för avancerat för mig. Kan bara pyttelite php.
Men jag tror att felet ligget i kodsnudden

    $images = explode("<img ", $imgcontent);            
            if (count($images) != "1") {            
            for ($i=0;$i<count($images);$i++) {
            
                if ($images[$i] != "") {
                    $image = str_replace('<img ','<div class="eachpost "><div><img ','<img '.$images[$i]);
                    $imagepieces = explode("/>", $image);
                    $imageurl = substr($imagepieces[0], 0, -2) . '" /></div></div>';
                    
                    $imagesrc_temp = explode('src="', $imageurl);
                    $imagesrc = explode('"', $imagesrc_temp[1]); // get src
                    
                    $imagew_temp = explode('width="', $imageurl);
                    $imagew = explode('"', $imagew_temp[1]); // get width
                    
                    $imageh_temp = explode('height="', $imageurl);
                    $imageh = explode('"', $imageh_temp[1]); // get height
                
                    $upload_path = get_option( 'upload_path' );
                    $upload_path = trim($upload_path);
                    $img_full_url = $imagesrc[0];

                    $temp = substr(strrchr($upload_path, "/"), 1);
            
                    list($url, $filename) = explode($temp, $img_full_url);
            
                    $img_url = $upload_path . "/" . $filename;
            
                    $imagesize = getimagesize($img_url);
                    list($width, $height, $type, $attr) = getimagesize($img_url);
                    $theClass = "eachpost ";
                    if ( $width < "440" ) { $new_width = "200"; $theClass = "eachpost "; } 
                        else if ( $width < "660" ) { $new_width = "430"; $theClass = "eachpost twocols"; }

som ser ut att återfinnas i både single.php och page.php.

Antingen en bit upp där det handlar om bildkällan, eller nästan längst ner där du har $new_width = "200"

Frågan är om det är du (eller någon annan) som har bestämt den bredden (200) genom att ange den på någon form av galleribilder i admin-gränssnittet ?

Annars går jag bet. Ropa på voigtann. :)

Medlem sedan jan. 20034 480 inlägg
#15

Det är jag som bestämt bildbredden till 200, så den passar in även för stora bilder i mallen.

Vi kanske bör ropa på mästaren... VOIGTANN!!!! HJÄLP!!!

Medlem sedan aug. 20068 090 inlägg
#16

magnusfeldth skrev:

Det är jag som bestämt bildbredden till 200, så den passar in även för stora bilder i mallen.

Ah... kanske har hittat spöket i alla fall då...har du kollat vad som händer om du tar bort den bredden, och/eller letar om det finns en annan inställning någonstans där den egentligen ska vara?

Alternativet, att du i stilmallen kanske kan lägga in bildbredd 200px på bilder i just de kolumnerna i.st.f. att ha bredden i databasen?

278 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
127 ms — deklarationer (db)
0 ms — hämta statistik (cache)
147 ms — hämta tråd, inlägg och bilagor (db)
128 ms — ändringar (db)