Month: July 2016

Loop through specific pages in WordPress

Sometimes you might want specific pages to be displayed on your site. If you want to display specific posts you can place them into the same category and loop though them by cat.  However, you can’t do that with pages.  In order to solve that, this is what you have to do if you want to loop through specific pages:

Copy this code where you would like to use it and in the assignment of variable $args modify the array with the IDs of the pages you want to use. In case you don’t know how to find your page ID, simply open up the editor for the Page you want.  In the URL area you will see the page number mentioned in the http string.  It will look something like this: ‘post=74’. That is your page ID number.  Check out this guide for a visual on how to do this.

Next, add your own content inside the loop. Don’t forget to close out your php tags if your content will include html. For example:

That’s it really.  Here is an example of the code of a loop through specific pages that i created to make a mosaic of images that link to specific pages.

Enjoy, and if you have any questions, leave them in the comments below.

 

How to add a guest author’s name to your post

So, someone has agreed to write an article for your WordPress blog and you want their name to appear next to the article.  There are two ways to add a guest author’s name.  First, you could always create an account for them and they can post their own articles.  This works well, especially if they plan to write again in the future.  The second way does not involve the author at all.  You simply add some code to your functions.php file and add a custom field at the bottom of your post.  This method is ideal when you don’t want to bother the author with dealing with passwords, when they will only write one article, when they have simply sent you the text of an article and will not be going into the WP editor to create the post and for keeping your dashboard clutter free.  On to it then.

Add a guest author’s name to your post

1.  FTP to your site and open the functions.php file in an editor and paste in this code snippet.  If you need a general purpose editor, I recommend Notepad++  it is lightweight, simple to use and free.  Download it here.

2.  Now that you have entered the code, go to your post editor, go to “Screen Options” and make sure that “Custom Fields” are selected.

add a guest author's name
add a guest author’s name

3. Scroll past your post and in the section “Custom Fields” click on “Enter New”

add-a-guest-author's-name-2

4. After that type “guest-author” exactly as I have written it in the “Name” field and type in the name of the author in the “Value” field

add-a-guest-author's-name-3

5.  Enter the content of the post and publish.  The guest name will appear.

messi

For any other WordPress questions you might have or just to discuss things WordPress, drop me a line.

 

Are you ready for a new website?

Yes, let's start!