Support » Plugins » Hacks » Looping a Category within the Functions Page

  • Hi Guys,

    This is the code i have implemented in my page. As you can see “url” and “url2” are already working in the page and this is displaying the RSS feeds correctly.

    The only problem is on the post itself there are 2 categories that need to be displayed. Currently its only displaying the 2 feed for one of the categories. What i need it to do is loop the other categories too and display the rss feeds.

    You will see in the coding below ive added the 2 additional rss feeds at the bottom, ive just got no idea how to generate it in the main PHP code. If someone could take a quick look that would be fab.

    Thanks in Advance.

    function themename_powerpress_player_links($content, $media_url, $ExtraData = array())
    $category = get_the_category();
    foreach((get_the_category()) as $category) {
    $catid = $category->cat_ID ;
    $url2 = get_category_link($catid) . "feed";
    $url = str_replace("http", "itpc", $url2); 
    $content .= ' '.POWERPRESS_LINK_SEPARATOR .' ';
    $content .= 'Subscribe Genre Via iTunes: <a href="'.$url.'">Click Here</a> <br>';
    $content .= ' '.POWERPRESS_LINK_SEPARATOR .' ';
    $content .= 'Subscribe To Genre Feed: <a href="'.$url2.'">Click Here</a><br>';
    $content .= ' '.POWERPRESS_LINK_SEPARATOR .' ';
    $content .= 'Subscribe To Artist iTunes: <a href="'.$url.'"> iTunes Artist Feed i.e. Chris Neon</a> <br>';
    $content .= ' '.POWERPRESS_LINK_SEPARATOR .' ';
    $content .= 'Subscribe To Artist Feed: <a href="'.$url2.'">Artist Feed i.e. Chris Neon</a><br>';
    return $content;
     add_filter('powerpress_player_links', 'themename_powerpress_player_links', 100, 3);
Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    You need to expand the foreach loop’s scope to include all the $content .= {add stuff}; statements.

    Right now, you get all the categories, step through each one returned, but then over write the value assigned to $catid before anything can be done with it. Only the last category gets anything done to it as there wasn’t anything else left to overwrite it.

Viewing 1 replies (of 1 total)
  • The topic ‘Looping a Category within the Functions Page’ is closed to new replies.