Domanda

voglio solo questo codice da aggiungere nel mio functions.php, in modo che verrà visualizzato direttamente dopo il mio finisce pubblicare Attualmente mi sto aggiungendo questo codice al mio single.php, ma voglio aggiungere questo è in functions.php, questo codice è l'uso di recuperare tutti i tweet del rispettivo conto, il codice è qui

<?php
function parse_twitter_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) {
  $feed = str_replace("&lt;", "<", $feed);
  $feed = str_replace("&gt;", ">", $feed);
  $clean = explode("<content type=\"html\">", $feed);

  $amount = count($clean) - 1;

  echo $prefix;

  for ($i = 1; $i <= $amount; $i++) {
    $cleaner = explode("</content>", $clean[$i]);
    echo $tweetprefix;
    echo $cleaner[0];
    echo $tweetsuffix;
  }

  echo $suffix;
}

function the_twitter_feed($username) {
  // $username = "Mba_"; // Your twitter username.
  $limit = "5"; // Number of tweets to pull in.

  /* These prefixes and suffixes will display before and after the entire block of tweets. */
  $prefix = ""; // Prefix - some text you want displayed before all your tweets.
  $suffix = ""; // Suffix - some text you want displayed after all your tweets.
  $tweetprefix = ""; // Tweet Prefix - some text you want displayed before each tweet.
  $tweetsuffix = "<br>"; // Tweet Suffix - some text you want displayed after each tweet.

  $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $limit;

  $twitterFeed = get_transient($feed);
  if (!$twitterFeed) {
    $twitterFeed = wp_remote_fopen($feed);
    set_transient($feed, $twitterFeed, 3600); // cache for an hour
  }
  if ($twitterFeed)
    parse_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix);
}
?>
È stato utile?

Soluzione

Non sono sicuro perché non basta inserire il codice nel single.php, o utilizzare la soluzione di Denis, ma se si vuole collegare in the_content è possibile farlo mettendo il seguente nel file functions.php :

function append_the_content($content) {
    $content .= 'PUT YOUR FUNCTION HERE';
       return $content;
}
add_filter('the_content', 'append_the_content');

Questo aggiungerà direttamente alla fine della the_content.

È possibile chiamare la funzione Twitter di sopra di questo e dovrebbe funzionare. Si sarebbe meglio utilizzare un quadro a tema con alcuni ganci personalizzati perché vadano in the_content in questo modo può diventare molto buggy molto veloce a seconda di ciò che gli altri filtri / ganci vostro tema e plugin utilizzano per modificare the_content. Non so perché succede, so solo che lo fa.

Altri suggerimenti

Utilizzando FTP, afferrare functions.php del vostro tema, e aggiungere il codice di cui sopra al suo interno, meno il leader <?php e la ?> finale, verso la fine della seconda del file (prima della ?>, che termina php).


Ho modificato la funzione in modo che possa essere utilizzato in un modello:

<?php the_twitter_feed('username'); ?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top