[resolved] Random quote in header (4 posts)

  1. posword
    Posted 7 years ago #

    I'm trying to get a random quote on my site. I have taken the code below from my legacy site but cannot get it to display anything within WordPress, regardless of the theme I am using. The code is as follows:

    	/* Pull quote from file for header                           */
        $quote = file("localhost/assets/wp-content/themes/atahualpa34/inchrist.txt");
    	$inquote = $quote[rand(1,count($quote))];
    	/* End pull quote                                       	*/

    I suspect the problem is in the "$quote = file("....); line. The text file with the quotes is in the theme's root directory. I have tried file("/inchrist.txt), file("inchrist.txt), as well as the full path above. I have tried it with and without the plugin Exec-PHP.

    The quote should display with the single line of code:
    <?php echo $inquote; ?>

    Can anyone point me in the right direction, please?


  2. Michael
    Forum Moderator
    Posted 7 years ago #

    i think the following code points to the root directory of the theme:
    <?php bloginfo('template_url'); ?>

  3. Mark / t31os

    Posted 7 years ago #

    So you'd use..
    $quote = file(get_bloginfo('template_directory').'/inchrist.txt');
    $quote = file(get_bloginfo('template_url').'/inchrist.txt');

    Or to make it a little easier to read..

    $quotepath = get_bloginfo('template_directory');
    $quote = file($quotepath.'/inchrist.txt');
  4. posword
    Posted 7 years ago #

    Thanks @alchymyth and @t31os. Got the syntax right with your help and its working. Much appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic