Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

I want to use a solution by @toschoa solution by @toscho to display and rotate some quotes. The unchanged code works very well, but if I replace the

protected function get_rand()
{
    return rand( 1, 1000 );
}

with (from herehere)

protected function get_rand()
{
    $array = file("wp-content/plugins/quotes-rotator/quotes.txt");
    $r = rand(0,count($array)-1);
    return $array[rand(0,count($array)-1)];
}

the code works well only at the first page load, but when I press the 'New' button to display a new quote the system outputs an error:

Warning: file(wp-content/plugins/quotes-rotator/quotes.txt): failed to open stream: No such file or directory in /var/www/.../public_html/wp-content/plugins/quotes-rotator/ajax-shortcode-demo.php on line 106

What is wrong here?

I want to use a solution by @toscho to display and rotate some quotes. The unchanged code works very well, but if I replace the

protected function get_rand()
{
    return rand( 1, 1000 );
}

with (from here)

protected function get_rand()
{
    $array = file("wp-content/plugins/quotes-rotator/quotes.txt");
    $r = rand(0,count($array)-1);
    return $array[rand(0,count($array)-1)];
}

the code works well only at the first page load, but when I press the 'New' button to display a new quote the system outputs an error:

Warning: file(wp-content/plugins/quotes-rotator/quotes.txt): failed to open stream: No such file or directory in /var/www/.../public_html/wp-content/plugins/quotes-rotator/ajax-shortcode-demo.php on line 106

What is wrong here?

I want to use a solution by @toscho to display and rotate some quotes. The unchanged code works very well, but if I replace the

protected function get_rand()
{
    return rand( 1, 1000 );
}

with (from here)

protected function get_rand()
{
    $array = file("wp-content/plugins/quotes-rotator/quotes.txt");
    $r = rand(0,count($array)-1);
    return $array[rand(0,count($array)-1)];
}

the code works well only at the first page load, but when I press the 'New' button to display a new quote the system outputs an error:

Warning: file(wp-content/plugins/quotes-rotator/quotes.txt): failed to open stream: No such file or directory in /var/www/.../public_html/wp-content/plugins/quotes-rotator/ajax-shortcode-demo.php on line 106

What is wrong here?

Source Link
Yuri
  • 1.1k
  • 4
  • 25
  • 46

Display random text from a file with the WP built-in AJAX API

I want to use a solution by @toscho to display and rotate some quotes. The unchanged code works very well, but if I replace the

protected function get_rand()
{
    return rand( 1, 1000 );
}

with (from here)

protected function get_rand()
{
    $array = file("wp-content/plugins/quotes-rotator/quotes.txt");
    $r = rand(0,count($array)-1);
    return $array[rand(0,count($array)-1)];
}

the code works well only at the first page load, but when I press the 'New' button to display a new quote the system outputs an error:

Warning: file(wp-content/plugins/quotes-rotator/quotes.txt): failed to open stream: No such file or directory in /var/www/.../public_html/wp-content/plugins/quotes-rotator/ajax-shortcode-demo.php on line 106

What is wrong here?