• Hello,

    I am totally not known with php, but try to integrate Twitter with the comments.

    The idea is that you can click a link which generates a hashtag on Twitter. And under each article I wanna publish the tweets with the specific hashtag.

    I solved the publishing, which look like:

    Use hashtag #MR_<?php the_ID(); ?> or <a href="https://twitter.com/home?status=MR_<?php the_ID(); ?>">click here</a><p>

    Now I wanna use WordPress built in rss reader to pull the comments on Twitter.

    <?php include_once(ABSPATH . WPINC . '/rss.php');
    wp_rss("https://search.twitter.com/search.atom?q=MR_<?php the_ID(); ?>)", 10); ?>

    That doesn’t work. I read that you can’t nest php functions. How can show an specific rss-feed under each article?

Viewing 6 replies - 1 through 6 (of 6 total)
  • instead of returning the value the_ID function print the value on screen.
    So here is one small hack to get it done.
    <?php include_once(ABSPATH . WPINC . ‘/rss.php’);
    ob_start();
    the_ID();
    $ID=ob_get_clean();
    wp_rss(“https://search.twitter.com/search.atom?q=MR_$ID)”, 10); ?>

    Enjoy… In India we call it a Jugaad

    What about using custom fields? I have a custom field called rss which stores the url to the rss feed for a site. I’d like to grab the value and place it into the wp_rss call.

    wp_rss("https://search.twitter.com/search.atom?q=MR_{$post->ID})", 10); ?>

    If you’re in a function, you’ll need to call global $post; before that.

    btw get_the_ID() function is also there.

    Hello
    Im having an issue with calling a custom field data into the feed url.

    I basically want a page to show a different feed url based on whats been inputed into the custom field option. How would i implement this using this setup.

    <?php
    	   $feeds =  get_post_meta($post->ID, 'feeds',true);
    ?>
    <?php
    	include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
    	$feed = fetch_rss('FEED-URL I WANT TO CALL FROM A CUSTOM FIELD'); // specify feed url
    	$items = array_slice($feed->items, 0, 3); // specify first item and duration
    ?>
    <?php if (!empty($items)) : ?>
    <?php foreach ($items as $item) : ?>
    <a href="<?php echo $item['link']; ?>"><?php echo $item['description']; ?></a>
    <?php endforeach; ?>
    <?php endif; ?>

    thanks in advanced to anyone with a solution.

    ISSUE RESOLVED!!!

    I used $feeds as my custom field option

    <?php // Get RSS Feed(s)
    							include_once(ABSPATH . WPINC . '/rss.php');
    							$feeds =  get_post_meta($post->ID, 'feeds',true);
    							$rss = fetch_rss($feeds);
    							$maxitems = 5;
    							$items = array_slice($rss->items,0,$maxitems);
    
    							?>
    
    							<ul>
    							<?php if (empty($items)) echo '<li>No items</li>';
    							else
    							foreach ( $items as $item ) : ?>
    							<li><a href='<?php echo $item['link']; ?>'
    							title='<?php echo $item['title']; ?>'>
    							<?php echo $item['title']; ?>
    							</a></li>
    							<?php endforeach; ?>
    							</ul>
    
    						</div>

    check out the link
    link

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘post_ID within a php function’ is closed to new replies.