• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.

Matching Recent WordPress Articles for XenForo Categories

wanderer.jpg


Members may have noticed a few changes were made last night and this morning to the categories pages of XenForo. In particular, five recent articles from WordPress which match the category are now shown. This is accomplished with a callback to a PHP file which uses the wp_get_recent_posts WordPress function.

Building the file was nothing more than extending the WPPostsWide.php file written earlier. An important change included adding the category argument to the array.

PHP:
$wp_args = array(
   'numberposts' => '5',
   'offset'      => 0,
   'category' => 2385,
   'post_type'   => 'post',
   'post_status' => 'publish'
);

$recentPosts = wp_get_recent_posts( $wp_args );

Each file contains a unique class name and resides in the TRN_XenWord_Model directory on the server.

The category is a number, which is easily found in WordPress admin panel Posts >> Categories. Hover over the edit button and look for the tag_id.

The template category_view was modified to include the callback to the PHP file.

Code:
<xen:if is="{$category.title} == 'Business & Finance'">
    <xen:callback class="TRN_XenWord_Model_WPPostsBusiness" method="getHtml"></xen:callback>
<xen:elseif is="{$category.title} == 'Education'" />
        <xen:callback class="TRN_XenWord_Model_WPPostsEducation" method="getHtml"></xen:callback>
<xen:elseif is="{$category.title} == 'Lifestyle'" />
        <xen:callback class="TRN_XenWord_Model_WPPostsLife" method="getHtml"></xen:callback>
<xen:elseif is="{$category.title} == 'Science'" />
        <xen:callback class="TRN_XenWord_Model_WPPostsScience" method="getHtml"></xen:callback>
<xen:elseif is="{$category.title} == 'Opinions'" />
        <xen:callback class="TRN_XenWord_Model_WPPostsStaff" method="getHtml"></xen:callback>
<xen:elseif is="{$category.title} == 'Technology'" />
        <xen:callback class="TRN_XenWord_Model_WPPostsTech" method="getHtml"></xen:callback>
<xen:elseif is="{$category.title} == 'US & World'" />
        <xen:callback class="TRN_XenWord_Model_WPPostsNews" method="getHtml"></xen:callback>
<xen:elseif is="{$category.title} == 'Webdesign Communities'" />
        <xen:callback class="TRN_XenWord_Model_WPPostsWebdesign" method="getHtml"></xen:callback>
<xen:else />
        <xen:callback class="TRN_XenWord_Model_WPPostsWide" method="getHtml"></xen:callback>
</xen:if>

After modifying the template, the sidebar still showed until realizing the widget framework was interfering.

This change, along with the XenFront add-on is starting to provide Tux Reports Community with a unique look. There are still plenty of work to do on the CSS but the site is starting to take a different look for the old 90s style forum.
  • Like
Reactions: robru

Blog entry information

Author
LPH
Views
2,314
Comments
1
Last update

More entries in General

More entries from LPH

Top