function getContent() help

Discussion in 'PHP' started by megler, Jan 11, 2008.

  1. #1
    I am a complete noob when it comes to php, so please bear with this hopefully simple question. I did google this before coming, to see if i could figure this out on my own, but just didn't find a simple enough answer.

    This is the code I'm using:

    /**
    		 * This is the content of the post.  This is where the output of
    		 * your plugin should go.  Just store the output from all your
    		 * plugin function calls, and put the output into this var.
    		 */
    		$post->post_content = $this->getContent();
    PHP:
    Then the output should be displayed here:
    
    
    	function getContent()
    	{
    		return '<p>Hi there!  You are viewing my fake post!</p>';
    	}
    
    PHP:
    I copied and pasted from 2 different parts of the plugin, so I may have missed something, but these are the parts I'm focusing on. Here's my question:

    If I want to change the output of the content to something else, say an array of sorts (blue, yellow, green) - how do I do that?

    I've tried putting what I want in the getContent function, but I don't know how to make it display later on instead of the "Hi there, you're are viewing my fake post..."

    Any help would be greatly appreciated! Thanks so much!

    Marceia
     
    megler, Jan 11, 2008 IP
  2. grikis

    grikis Banned

    Messages:
    333
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    function getContent()
    {
    $a = "<p>Hi there! You are viewing my fake post!</p>";
    return $a;
    }

    $post->post_content = getContent();

    try this
     
    grikis, Jan 11, 2008 IP
  3. megler

    megler Peon

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I originally wrote a reply saying I didn't understand the need for the variable of $a, but then i went and tried and and it works fine. you're awesome. One new question:

    how could i can I make this an array and randomize this?

    1. red
    2. green
    3. blue

    and have the getContent() spit those out in random order? I know the very basics of arrays and I know that random is random(), but not sure how to put that all together with the getContent...

    I think that's my last question, you definitely put me in the right direction! thanks!!!!!
     
    megler, Jan 11, 2008 IP
  4. megler

    megler Peon

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I actually figured it out myself. I can't believe i did it! LOL. here's what I did:

    function getContent()
    	{
    	$a = array
    	('red', 'blue','green', 'purple','yellow','black');
    	 
    	 // Gets the Total number of Items in the array
        <br>
    $totalqts = (count($a)/2);
    <br>
    // Subtracted 1 from the total because '0' is not accounted for otherwise
    $nmbr = (rand(0,($totalqts-1)));
    $nmbr = $nmbr*2;
    <br>
    $quote = $a[$nmbr];
    $nmbr = $nmbr+1;
    <BR><BR>
    
        return $quote;
    PHP:
    Thanks again so much. I would have never figured out that first part without your help. :)
     
    megler, Jan 11, 2008 IP