LPH
Well-known member
The thread_id is known and I'd like to pull the first_post_likes based on that thread_id.
This code does the above through an SQL statement. Since I'm trying to learn the "XenForo way" ... the next step is to take this code and change it to using XenForo_Model_Thread and getThreads or should it be getThreadsID?
Here is working code:
The place to focus:
I'm trying to learn this one from scratch rather than copy pasting from previous pulling of thread content.
Somehow I want to grab XenForo_Model_Thread::FETCH_FIRSTPOST, correct?
This code does the above through an SQL statement. Since I'm trying to learn the "XenForo way" ... the next step is to take this code and change it to using XenForo_Model_Thread and getThreads or should it be getThreadsID?
Here is working code:
PHP:
<?php
/**
* Filename: class-xenword-postratings.php
*
* Description: Shows the post ratings of the first post in a thread on the WordPress post.
*
* @since 2.5.1.01
* Initial release
*
*/
/**
* This section is for security. Do not modify this part:
* @ignore
*/
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Pull the likes from the first_post likes in the xf_thread table based on the thread_id
* then return the number of likes to the WordPress $content
*
* @param $content
*
* @return string
* @throws Zend_Exception
*/
function show_postratings( $content ) {
/** Load the XenWord options set in XenWord settings panel */
$xenword_options = get_option( 'xenword_options' );
if ( $xenword_options['use_postratings'] == true ) {
if ( is_singular() && is_main_query() ) {
$post_id = '';
$post = get_post( $post_id, ARRAY_A );
if ( $post['thread_id'] != '0' ) {
// Show Post Ratings
$thread_id = $post['thread_id'];
$first_post_id_qry = "
SELECT `thread_id`, `first_post_likes` FROM `xf_thread`
WHERE `thread_id` = $thread_id
";
$xen_post_id = XenForo_Application::get( 'db' )->fetchAll( $first_post_id_qry );
$xen_first_post_likes= $xen_post_id[0]['first_post_likes'];
$xenword_postratings = '
<span style="font-size: x-small; float: right">Post Ratings:<br />'
. $xen_first_post_likes
. ' likes</span>
';
$content .= $xenword_postratings;
}
}
}
/** return the WordPress post content with the post ratings included */
return $content;
}
add_filter( 'the_content', 'show_postratings' );
// End class-xenword-postratings.php
The place to focus:
PHP:
$thread_id = $post['thread_id'];
$first_post_id_qry = "
SELECT `thread_id`, `first_post_likes` FROM `xf_thread`
WHERE `thread_id` = $thread_id
";
$xen_post_id = XenForo_Application::get( 'db' )->fetchAll( $first_post_id_qry );
I'm trying to learn this one from scratch rather than copy pasting from previous pulling of thread content.
Somehow I want to grab XenForo_Model_Thread::FETCH_FIRSTPOST, correct?