treehouse : what would you like to learn today?
Web Design Web Development iOS Development

SimplePie/Wordpress Question

  • Is it possible for SimplePie to filter out posts from a feed?

    I'm working on a Wordpress beta site and I am trying to setup SimplePie to only display posts from my feed that have a specific category attached to them. Is this possible?

    The url of what I'm trying to do is here: http://trombonetranscriptions.com/wordpress/transcriptions/artists/j-j-johnson/

    I have created a post and attached a category of "J.J. Johnson" to it. On this particular page, I would like ONLY this post to show up in the feed.

    Thanks for any and all help!

    PS - this is my first post on the forum and apologize if this should be in the php forum...i wasn't sure...
  • I think maybe the answer is at http://simplepie.org/wiki/reference/simplepie_category/start but because I'm pretty new to this, I'm pretty confused...
  • Looks like I'm just going to have a discussion with myself because I'm just too impatient to sit here and am continually stumbling on some answers...hopefully someone gets something out of this...

    I've figured out that the categories in WordPress create feeds of their own. Therefore to pull just my posts with the JJ Johnson category I have to point to the feed created by this category. This is awesome!

    Now...

    I inserted
    <?php echo SimplePieWP('http://trombonetranscriptions.com/wordpress/category/artists/j-j-johnson/feed'); ?>
    into the page.php template to achieve this. I would rather not create numerous templates for the sole purpose of entering the correct feed into each one. Is there any way I can have the feed url dynamically created in the template?
  • Well, I actually ended up figuring this out on my own with the help of lots of Google searches. I'm completely new to PHP and although it confuses the heck out of me, I'm really impressed with how powerful it is. Below is all the code for my template.

    <?php
    /*
    Template Name: Artist Template
    */
    ?>

    <?php

    $postname = $_SERVER['REQUEST_URI'];
    $postname = str_replace(\"/\",\"\",$postname);
    $postname = str_replace(\"wordpress\",\"\",$postname);
    $postname = str_replace(\"artists\",\"\",$postname);
    $postname = str_replace(\"transcriptions\",\"\",$postname);

    ?>


    <?php
    /**
    * @package WordPress
    * @subpackage Default_Theme
    */

    get_header(); ?>

    <div id=\"content\" class=\"narrowcolumn\" role=\"main\">

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class=\"post\" id=\"post-<?php the_ID(); ?>\">
    <h2><?php the_title(); ?></h2>
    <div class=\"entry\">
    <?php the_content('<p class=\"serif\">Read the rest of this page &raquo;</p>'); ?>

    <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>

    <?php echo SimplePieWP('http://trombonetranscriptions.com/wordpress/category/artists/' . $postname . '/feed'); ?>

    </div>
    </div>
    <?php endwhile; endif; ?>
    <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>


    LIke I said, I'm completely new to PHP so if any of this looks 'janky' or problematic, please let me know.

    Link to the page is http://trombonetranscriptions.com/wordpress/transcriptions/artists/j-j-johnson/
  • haha well done yardle!
  • thanks doc.

    going through that process was a great learning experience for me, however, i found a better method for what i need to do.

    check out the AZIndex plug-in (http://wordpress.org/extend/plugins/azindex/) for Wordpress. it creates a page, then lists all the posts on that page that fall into the category(s) you specify. it will list them alphabetically (which is why i'm going this route instead) or in any other kind of order you need. good stuff.