webForumDet fria alternativet

Håller på med en liten mall till WP och behöver lite hjälp

Webbutveckling

2 svar · 525 visningar · startad av Fredde Mannen

Medlem sedan nov. 20014 054 inlägg
Frågan#1
<?php
/*
Template Name: Wedding
*/
?>
<?php get_header(); ?>
	<div id="content" class="widecolumn">
		<div id="post-<?php the_ID(); ?>" class="post-<?php the_ID(); ?> page">
			<h1><?php the_title(); ?></h1>
					<div class="postmeta">
						<span class="comments"><?php comments_popup_link(__('0 <span>comments</span>', 'notesblog'), __('1 <span>comment</span>', 'notesblog'), __('% <span>comments</span>', 'notesblog'), '', ''); ?></span>
						<span class="author"><?php _e("By", "notesblog");?> <a href="<?php the_author_url(); ?>" title="<?php the_author(); ?>" class="author"><?php the_author(); ?></a></span>
</div>

<div class="entry">
	<?php the_content(); ?>
 <ul>
<?php $recent = new WP_Query("cat=126&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a></li>
<?php endwhile; ?>
 </ul>
</div>

</div>
<?php 
comments_template(); 
?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Visst den listade posterna från kategorin, men sedan ville jag funktion att kunna kommentera sidan, så jag lade till det.

Men när man skriver en kommentar så tar den post id från den den sista posten av de som skrivits ut. Och det vill jag ju inte.

Hur undan komma detta?

Medlem sedan nov. 20014 054 inlägg
#2

Löste det med efter :

<?php get_header(); ?>
<?php 
 $thePostID = $post->ID;
?>
.... bla bla resterande kod innan comments_template... 
<?php 
$id = $thePostID;
comments_template(); 
?>

Så fick jag rätt ID för kommentarerna. :D

Medlem sedan nov. 20014 054 inlägg
#3

Fick göra en liten justering för att den skulle skriva ut posterna också..

<?php 
$post = get_post($thePostID); 
$id = $post->ID;
comments_template('', false); 
?>

Sen om det är en korrekt lösning och den bästa.. det vet jag inte!

471 ms totalt · 4 externa anrop · v20260731065814-full.86ec41c2
126 ms — deklarationer (db)
0 ms — hämta statistik (cache)
342 ms — hämta tråd, inlägg och bilagor (db)
126 ms — ändringar (db)