How to run php code in WordPress

When running a blog, you often face the problem that you want to execute PHP code to customize your site. I love Quotes and want to realize a “daily Quote” on my page. I tried to do it without one of the numerous plugins since we normally don’t want additional plugin ballast, nor another plugin that has to be constantly updated. I’ve found some outdated customizations of the function.php file, but nothing of them worked. Since I will use PHP customization in the future, I decided to use a plugin named “PHP Code Widget”.

Let’s get into it.

After installing the plugin, you can use it as a normal text field, which can interpret the PHP Code.
As always, the first thing is a “hello world” to test if the code is working.

echo 'Hello World!';

After that, I thought about showing a random Quote each time a user opens the website. I have plenty of Quotes and will code them hard in that text field. No database. For that, I need a random number which will be the index for my Array.

int random_int ( int $min , int $max )

With an array, it could be looking like this. We need an array filled with quotes and an echo which chooses one of them. Reminder: array indices start with 0, that’s why I used “-1” after the Array count. I count the array because if I add or delete one, I don’t have to change the maximum random number.

$quotes = array(
"Quote1",
"Quote2",
"Quote3"
);

// Random Quote each time the site is refreshed
echo $quotes[mt_rand(0, count($quotes)-1)]; 

My last edit was to put in the daily thing. With this code above you get a new quote each time you move through the website. I want to see a new one only each day. So we need a timestamp and modulo of all quotes as an index.


$quotes= array(
"Fall down seven times - Get up eight.",
"Stop wishing - start doing.",
"Don't call it a dream, call it a plan."
);

// Dayly Quote - one Quote for each day
echo $quotes[date("dmY")%count($quotes)];

That’s it. Hope you like the new collection of my motivating quotes I’ve collected over the years 🙂

My journey of starting programming

Back in 2010, I was 15 and on the way to get my A-Level in three years. Back in that time I was playing many games and wasting my time on it. I knew it was a kind of waste, but there was no other option to get so much fun. These games gave me a goal to reach in my spare time beside my sports. In one game, a farming browser game, I had to place crops, wait till they grew, harvested them and repeated this process. Soon I started to have more than one account, to play while the other account had to wait. I didn’t know something about programming, but my dad did. I asked him to write a program for me, which can do the login and farming thing for me, that I can do the other things in the game, which are way more fun. He replied he will help me doing it, but I had to do it by myself. He will help me with any questions I got and show me the basics of programming, but I had to do it on my own. My vision was created. I want to learn to programme to be the best player on the server. Sure it was cheating, but who cares.

Time investing VS time wasting

I started to invest my time in programming and growing my farm accounts. Soon I had five Accounts who worked fully automatically for me and my main in-game account. My “in-game business” grew and had nothing to do with the original sense of the game. You could say my first five employees worked for the chef of this little business. I spent afternoon and afternoon to improve my in-game money printer. Finally, some of my friends saw that I was rich on the server he was playing on. He offered me five euro for some in-game money, I made a mass of doing nothing. Of course, I replied yes! Free Pizza this afternoon!

Money creates more Money

Real money for giving you something I generate with my program? That’s a nice idea. I started programming harder and producing more online currency to sell. Soon my shitty laptop was too bad to run my programm a multiple time, so I decided to buy an extra one, just for running the program. Back in time, there was no cloud computing 😉
I bought them with money I got from selling my in-game money, so no loss, just invest to increase my sales. First experience where money is making more money. In that step I had 100 Accounts running, and my main Account was one of the best 50 players in the server. Can you imagine what’s going on in my mind?

Time to expand my mini business

An idea grows in my mind. When classmates will give me money, then there must be others who will. A nice website named eBay will help me. I set my first auction, with the note, that they won’t pay for the in-game money, but for an access data to an account with a decent amount of in-game money. Of course, they will transfer it to their main account, but the rules of the game prohibited selling in-game currency, but not selling Accounts. The first auction sold five times higher than my classmates gave me for the same amount. Simply supply and demand I guess. There was no one like me on eBay. I now had the opportunity to use my time for a dream I made myself and had a real impact on the monthly money I had per month. Great!

“International” expansion

My 100 accounts where central in one server, which means they can’t trade with players of other servers. Since my customers were not only on the server I played on, I had to become “international” — active on all servers. 100 Accounts on each Server? No problem. It needs just more technical upgrades. Some servers were older and with it inflation more advanced. The in-game money was, therefore, less worth. That means more effort for me for the same amount of Euros. Finally, my little business produced more in-game money, than needed. The peak is reached. From then on, I made money passively. Over time, however, the game lost to players until sales barely dropped to more than a few euros a week. I never found a simiar game, but the experience I will never forget.

Conclusion

I was just a kid without any programming knowledge. But I thought I can do it, so I did it. Think who you like to be and write down the steps which are needed. Then simply start with it. Little baby steps. One after the other.

Why your whole life can be a big game – reach your goals more easily

Imagine you are climbing a mountain with a friend, but you slide down at one point and fall into the depths. You are now lying in a dark crevice, your friend can no longer hear you and cuts the rope to you because he thinks you have been killed. You’re alone and your leg’s not doing too well either. This is how the climber Joe Simpson, who made a game out of this situation in order to save himself. This post is based on the book Barking up the wrong tree by Eric Barker, I’ve read this weekend. Here’s my summary for you.

Below are the four basic parts of each game that he used to survive:

Reachable

The goals must be attainable for yourself. As a rule of thumb, the author mentions here at least 20% of the time that is devoted to the task you should believe yourself that you can do it. Otherwise, the target is set too high. In the case of the climber, he dragged himself from visible hill to hill, up to the camp from which they set out. When he reached a small goal, he celebrated himself. If he didn’t, he reflected why not and put in a new one. So he crawled until he could see the camp and call for help to be rescued by his friend.
These small “levels” have kept him on the big goal, until success.

If you set yourself a goal, make it a challenge, but an achievable one.

New challenges

Monotony paralyzes us. Something becomes increasingly boring the more often we have to do the same job. In computer games the same mechanics are often used. The levels look different and other ways to reach the goal are needed. So it remains interesting.
A way to use it in a relaxed life: Set your own time limits. The “level” becomes more difficult because it has to be completed in less time. For example, I give myself a time limit for animating my videos. Instead of 4h for one part, I give myself only 3h and see if I can finish animating it. When I made it, I saved an hour. If I don’t make it, however, the increased pressure will make me realize where the potential for improvement has now been uncovered. In this context, the 80/20 rule can be very advantageous. Also: “Better done than perfect!”

New challenges motivate and can be created in all situations.

Clear goals

The goal has been achieved, or not. Black or white. Is the article ready to be published or not? Once it’s released, there’s no turning back. For our climber: has he reached the hill or not. SMART targets can help here:

Simple: what is achieved and who achieves it.
Measurable:  How much of something, for example, to create the animation in a given time. The clock has run out or not.
Achievable: The goals must be achievable for you as a person. If possible in a small window of time, so as not to lose the desire too quickly.
Realistic: Being three times faster than setting goals is not really realistic. It has to be a challenge and nothing that is completely impossible. Even if it’s only impossible at this point in time.
Time limited: Our climber set himself 20 minutes for each additional goal to precisely measure his progress and define small packages that could be reached.

Feedback

In games, we get feedback about achievements and experience points. With every little bit, we get closer to our goal. We notice directly whether we are approaching our goal or moving away from it. That’s why it’s good to set yourself small goals and maybe even mark them in your calendar.
The internet is the perfect place to get feedback, which is why I also publish here. Only with feedback from others can one’s own work become better.

Summary in one sentence

If you need the motivation to go a little further, turn the activity into a game and the motivation will come.

Our best quotes listed for your motivation!

We all know them. quotes that motivate us and make us think in new directions. I’ve put together my favorite quotes for you here, with my interpretation of those:

Don’t call it a dream, call it a plan

See your Dream as a plan which will be planned and lived. Plan your way and then just do it.

 

Don’t limit your challenges. Challenge your limits.

Think outside the box and leave your comfort zone. Be curious and test your limits.

 

Fall down seven times – Get up eight
Mistakes are proof that you are Trying!

You have to fail to gain wins. If you are afraid of losing, you will never try.

 

Winners don’t make excuses

Far too often we lie to ourselves that something doesn’t have to be done when we know we should.

 

Don’t let yesterday take up too much of today

Don’t pay too much attention to the past and look forward. The past can no longer be changed, but we ourselves are shaping our future.

 

What would you do if you weren’t afraid?

As mentioned above, fears hold us back. Push forward! Defeat your fear.

 

I never lose, either I win or I learn.

In school, we learn that mistakes are bad. the students with the best grades are the ones with the fewest mistakes. in real life, the curious are the successful ones. Only those who fail a lot can do a lot because they try and learn from their failure.

 

Let no one stop you!

You have a dream, a goal. No matter what others say, go and find friends with the same goal. Pessimists see only the bad and not the opportunities that are possible.

 

Make goals, Dream big, live with passion

I think it’s all said. Good Luck my friend!