每个帖子后的随机引号wordpress

时间:2018-01-21 18:10:55

标签: php wordpress

我已经启动了一个新的插件,它假设在每个帖子后显示随机引号 它没有给出任何错误,但它现在显示我的帖子之后的任何文字。 我试过这种方式,但似乎我失败了一些。 我没有得到任何错误,但在激活它假设显示随机文本但没有,我无法使其工作。 看了我的代码后,我试着修改 并且没有错误,但我的代码仍然没有显示文本

Firt我劝你@mangenta寻求帮助 但我的第一个问题是同样的问题 我想将引号变量$ quote传递给签名位置但似乎不起作用。 我的帖子之后没有显示我的文字,就像我需要的那样,我无法通过任何方式通过 引号变量为签名代码     这是我的代码

<?php
/*
Plugin Name: Random Text Quotes
Version: 1.0
Description: Random Text Quotes Albert Einstein.
Plugin URI: https://mediaads.eu/
 Author: Helder Ventura
 Author URI: https://mediaads.eu
 Version: (standalone)
 Usage: install activate and done
 */
 $bgcolor = '#FFFFCC';
 $textcolor = 'black';
$textsize = '2';
// Array Structure:  "Quote","Author"
$allqts = array
("*His aim was to substitute for a petrified and barren
system of ideas the unbiased and strenuous quest
for a deeper and more consistent comprehension of
physical and astronomical facts.", 
    "Albert Einstein",
"The discovery and use of scientific reasoning by
Galileo was one of the most important achievements
in the history of human thought.<br>" ,
    "Albert Einstein",
"I admire Gandhi greatly but I believe there are two
weaknesses in his program.",
    "Albert Einstein",
"I believe that Gandhi’s views were the most enlightened
among all of the political men of our time.",
    "Albert Einstein",
"Liberty, when it begins to take root, is a plant of rapid growth.", 
    "George Washington",
"Gandhi, the greatest political genius of our time,
indicated the path to be taken.",
    "Albert Einstein",
"Gandhi’s development resulted from extraordinary
intellectual and moral forces in combination with
political ingenuity and a unique situation.",
    "Albert Einstein",
"Anyone who has never made a mistake has never tried anything new",
    "Albert Einstein",
"Progress doesn't come from early risers, progress is made<br>by lazy men 
looking for easier ways to do things.",
    "Lazarus Long <font size=-2>(Time Enough for Love by Robert A. Heinlein)
</font>",
"On Johann Wolfgang von Goethe (1749–1832)
I feel in him a certain condescending attitude toward
the reader, and miss the humility that is comforting,
especially when it comes from great men.",
    "Albert Einstein",
"*This was the first time I’ve ever heard of such
an important man who speaks at least briefly with
his mother every day.",
    "Albert Einstein",
"On Werner Heisenberg (1901–1976)
Professor Heisenberg was here, a German.",
    "Albert Einstein",
"I am very happy here and enjoying the American
summer as well as the news about Hitler’s mad
deed of desperation.",
    "Albert Einstein",
"Hitler appeared, a man with limited intellectual
abilities and unfit for any useful work, bursting with
envy and bitterness against all whom circumstance
and nature had favored over him. . . .",
    "Albert Einstein",
"*I haven’t forgotten that the Swiss authorities didn’t
stand by me in any way when Hitler stole all of my
savings, even those designated for my children.",
    "Albert Einstein",
"On Immanuel Kant (1724–1804)
*Kant’s much-praised view on Time reminds me of
Andersen’s tale of the emperor’s new clothes, only
that instead of the emperor’s new clothes we have
the form of intuition.",
    "Albert Einstein",
"*Kant is sort of a highway with lots and lots of milestones.
Then all the little dogs come and each deposits
his contribution at the milestones.",
    "Albert Einstein",
"What seems to me the most important thing in
 Kant’s philosophy is that it speaks of a priori concepts
 for the construction of science.",
    "Albert Einstein",
 "Kant, thoroughly convinced of the indispensability
 of certain concepts, took them—just as they are selected—to
 be the necessary premises for every kind
 of thinking and differentiated them from concepts
 of empirical origin.",
    "Albert Einstein",
"On George Kennan (1904–2005)
Princeton University Press sent me George Kennan’s
new book [Realities of American Foreign Policy] and I
read it right away.",
        "Albert Einstein",
"[Kepler] belonged to those few who cannot do otherwise
than openly acknowledge their convictions
on every subject. . . .",
    "Albert Einstein",
"There we meet a finely sensitive person, passionately
dedicated to the search for a deeper insight into the
essence of natural events, who, despite internal and
external difficulties, reached his loftily placed goal.",
    "Albert Einstein",
    "Share Your Love With The World.",
    "Helder Ventura"
    );

  // Gets the Total number of Items in the array
  //  Divides by 2 because there is a Quote followed by an Author
 $totalqts = (count($allqts)/2);

 // Subtracted 1 from the total because '0' is not accounted for otherwise
 $nmbr = (rand(0,($totalqts-1)));
 $nmbr = $nmbr*2;

//$nmbr = 18;

$quote = $allqts[$nmbr];
     $nmbr = $nmbr+1;
$author = $allqts[$nmbr];

// You can delete this section
//   it is only so Search engines can find it
if ($_SERVER['PHP_SELF'] == "/quotes.php") {
echo "<Title>Random Text Quote</title>";
echo "<meta name=\"Description\" content=\"Random Text Quote\">";
echo "<meta name=\"keywords\" content=\"Random Text Quote\">";
}
/// End Delete


$space = "<font color=$bgcolor>.....................................</font>";
$comments = "<br><center><font size='-2'><i><a href='quotes.php'>Random Text 
Quote</a></i></font></center>";

echo "<center>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<Font color=$textcolor size='$textsize'><i>";
echo "$quote<br>";
echo "</i></font>";
echo "$space $author";
echo "$comments";
echo "</center>";
// You can delete this section as well - it's my shameless plug:
//   it is only so Search engines can find it
if ($_SERVER['PHP_SELF'] == "/quotes.php") {
    echo "<br/><br/>If you <i>really</i> like it, I do accept donations via 
PayPal: <a href='http://zonadelike.publiadds.org.pt//donate'>Donations</a>";
echo "<br/><br/>";
}
/// End Delete


IF ($_SERVER['PHP_SELF'] == "/quotes.php") {
show_source("quotes.php");
}
// Add Signature Image after single post
add_filter('the_content','add_signature', 1);
function add_signature($text) {
global $post;
if(($post->post_type == 'post')) 
$text .= '<div class="signature"><a href="https://mediaads.eu/" 
target="_blank" title=$text>'.$quote.'</a></div>';


return $text;
}
?>

1 个答案:

答案 0 :(得分:1)

我测试了原始帖子中的以下代码。

<?php
/*
Plugin Name: Random Text Quotes
Version: 1.0
Description: Random Text Quotes Albert Einstein.
Plugin URI: https://mediaads.eu/
Author: Helder Ventura
Author URI: https://mediaads.eu
Version: (standalone)
Usage: install activate and done
*/
function ab_arq_generate() {
$quotes = array(
    'I am happy to be in Boston. I have heard of Boston
as one of the most famous cities in the world and the
center of education. I am happy to be here and expect
to enjoy my visit to this city and to Harvard.
On his visit to the city with Chaim Weizmann. New York
Times, May 17, 1921. Contributed by A. J. Kox in response
to the many quotations about Princeton in this book (see
later in this section).',
    '*America is interesting, with all its hustle and bustle.
It is easier to feel enthusiasm for it than for other
countries I’ve unsettled with my presence. I had to
consent to being shown around like a prize ox to address
innumerable small and large gatherings. . . .
It’s a wonder I survived it all.
To Michele Besso, ca. May 21–30, 1921. CPAE, Vol. 12,
Doc. 141',
    '*It is the women . . . who dominate all of American
life. The men are interested in nothing at all; they
work, work as I haven’t seen anyone work anywhere
else. For the rest, they are toy dogs for their
wives, who spend the money in the most excessive
fashion and who shroud themselves in a veil of
extravagance.
From an interview in the Nieuwe Rotterdamsche Courant,
July 4, 1921. Einstein insisted he was wrongly quoted and
wrote a rebuttal in the Vossische Zeitung six days later,
claiming he was shocked when he read the account. ',
    'Even if Americans are less scholarly than Germans,
they do have more enthusiasm and energy, causing
a wider dissemination of new ideas among the
people.
Quoted in the New York Times, July 12, 1921
',
    'A firm approach is indispensable everywhere in
America; otherwise one receives no payment and
little esteem.
To Maurice Solovine, January 14, 1922. Published in Letters
to Solovine, 49. Einstein Archives 21-157'
);

return $quotes[rand(0, count($quotes)-1)];
}

function ab_arq_change_bloginfo( $text, $show ) {
if( 'description' == $show ) {
    $text = ab_arq_generate();
}
return $text;
}

  add_filter( 'bloginfo', 'ab_arq_change_bloginfo', 10, 2 );

 // Add Signature Image after single post
 add_filter('the_content','add_signature', 1);
function add_signature($text) {
 global $post;
 if(($post->post_type == 'post')) 
    $text .= '<div class="signature"><a href="https://mediaads.eu/" 
 target="_blank" title=$text>AAAAA</a></div>';


return $text;
}
?>

我做的唯一改变是我添加了文字&#39; AAAAA&#39;在您的签名A元素中,因为它没有文本内容。

此代码使用2016主题在我的网站上运行。因此,代码本身没有任何问题。我会尝试一个不同的主题,看看你使用的主题是否是问题的根源 - 我会尝试2016年,因为它已知在我的环境中工作。要运行主题代码,必须调用某些过滤器 - &#39; blog_info&#39;,&#39; the_content&#39; - 此外,&#39; blog_info&#39;必须使用参数&#39; description&#39;来调用过滤器。有些主题可能不会这样做。过滤器&#39; the_content&#39;可能被调用但没有产生任何可见内容,因为你的A元素没有文字内容。

更新代码 - 将报价从标语位置移动到签名位置

<?php
/*
Plugin Name: Random Text Quotes
Version: 1.0
Description: Random Text Quotes Albert Einstein.
Plugin URI: https://mediaads.eu/
Author: Helder Ventura
Author URI: https://mediaads.eu
Version: (standalone)
Usage: install activate and done
*/
function ab_arq_generate() {
    $quotes = array(
        'I am happy to be in Boston. I have heard of Boston
    as one of the most famous cities in the world and the
    center of education. I am happy to be here and expect
    to enjoy my visit to this city and to Harvard.
    On his visit to the city with Chaim Weizmann. New York
    Times, May 17, 1921. Contributed by A. J. Kox in response
    to the many quotations about Princeton in this book (see
    later in this section).',
        '*America is interesting, with all its hustle and bustle.
    It is easier to feel enthusiasm for it than for other
    countries I’ve unsettled with my presence. I had to
    consent to being shown around like a prize ox to address
    innumerable small and large gatherings. . . .
    It’s a wonder I survived it all.
    To Michele Besso, ca. May 21–30, 1921. CPAE, Vol. 12,
    Doc. 141',
        '*It is the women . . . who dominate all of American
    life. The men are interested in nothing at all; they
    work, work as I haven’t seen anyone work anywhere
    else. For the rest, they are toy dogs for their
    wives, who spend the money in the most excessive
    fashion and who shroud themselves in a veil of
    extravagance.
    From an interview in the Nieuwe Rotterdamsche Courant,
    July 4, 1921. Einstein insisted he was wrongly quoted and
    wrote a rebuttal in the Vossische Zeitung six days later,
    claiming he was shocked when he read the account. ',
        'Even if Americans are less scholarly than Germans,
    they do have more enthusiasm and energy, causing
    a wider dissemination of new ideas among the
    people.
    Quoted in the New York Times, July 12, 1921
    ',
        'A firm approach is indispensable everywhere in
    America; otherwise one receives no payment and
    little esteem.
    To Maurice Solovine, January 14, 1922. Published in Letters
    to Solovine, 49. Einstein Archives 21-157'
    );

    return $quotes[rand(0, count($quotes)-1)];
}

 // Add Signature Image after single post
 add_filter('the_content','add_signature', 1);
function add_signature($text) {
     global $post;
     if(($post->post_type == 'post')) 
        $text .= '<div class="signature"><a href="https://mediaads.eu/" 
     target="_blank" title=$text>' . ab_arq_generate() . '</a></div>';


    return $text;
}
?>