go41

Display excerpt of first and last post in front-page.php

von Joern am 16. Okt. 2010 | Keine Kommentare

As you can see I am displaying the first posts excerpt here in this bbPress forum by running
make_excerpt(get_post_text($post->post_id));
and the last answers excerpt by using
make_excerpt( get_post_text( $topic->topic_last_post_id ) );
The problem arising is that with only one post it will display the text twice, as the first post is also the last one.
The full code I use so far is:
Code:

<p class="quest">
<?php $post = bb_get_first_post(get_topic_id());
echo make_excerpt(get_post_text($post->post_id)); ?>
</p>
<p class="ans">
<?php echo make_excerpt( get_post_text( $topic->topic_last_post_id ) ); ?>
</p>

To solve this I am going to echo The ID of each post to see what’s going on.

I want to show an answer only if the first post’s ID $post->post_id is not equal to $topic->topic_last_post_id.
The code above with an echo of the ID:

Code:

<p class="quest">
<?php $post = bb_get_first_post(get_topic_id());
echo $post->post_id;
echo make_excerpt(get_post_text($post->post_id)); ?>
</p>
<p class="ans">
<?php echo $topic->topic_last_post_id;
echo make_excerpt( get_post_text( $topic->topic_last_post_id ) ); ?>
</p>

Have to post now to see something .. ;-)

How I did it will come as soon it works in the answer to this post
____________________
you find me on Google+, Twitter and Facebook

(von: Joern)

Hier noch 1 weitere Ergebnisse dieses Threads:

Re: Display excerpt of first and last post in front-page.php :: Reply by Joern

16. Okt. 2010 (von: Joern)

That was easier than expected!I used the condition:if ($post->post_id != $topic->topic_last_post_id )to display the excerpt of the answer only if is not the question itselfThe working code looks now like this:Code:<p class="quest"><?php $post = bb_get_first_post(get_topic_id());echo make_excerpt(get_post_text($post->post_id)); ?></p><?php if ($post->post_id !=…

Autor:

Du findest mich auch auf Google+, Twitter und Facebook!

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.


weitere forum Beiträge: