Posts categorized: PHP
WordPress provides a widget that can be used to display recent posts in any sidebar or widgetized location. Likewise many WordPress themes provide some sort of "recent post" functionality, so users can display their latest posts in specific locations around the theme. Such functionality is great and useful for displaying recent posts just about anywhere in your theme. Problem is, those methods don't work for displaying recent posts inside of posts, pages, and custom post types. Like inside of post content itself. For that, we can use a shortcode.
For years WordPress post navigation has been possible thanks to a flexible set of five functions, including
next_posts_link(). These navigational functions continue to work great in many WordPress themes, but there are newer, even more flexible functions available to theme developers. Introduced in WordPress 4, these new navigation functions can make it easier than ever to display nav links for your WordPress-powered posts.
After taking the time to set a whole bunch of theme options, it's nice to be able to make a quick backup of your theme settings. Many themes have this functionality built-in, but for themes that don't, here is a plug-n-play snippet to create a "Backup/Restore Theme Options" page. You can see the technique in action in my shapeSpace theme (100% free and open-source WordPress starter theme).
An easy way for visitors to enter their emails is by commenting on a post. We did this recently for people to sign up for a notification email. Instead of using a plugin or custom function for a one-time email list, we just went with WordPress core functionality and used post comments for people to sign up. Then the trick is retrieving the comment information from the database for the sign-up post.
A cool trick you can do with WordPress is display information directly from your theme's
style.css stylesheet. I recently used this on a site where the theme's version number is used throughout the template to keep things current and consistent.
Recently I worked on a project where a single RSS feed was imported and displayed in multiple columns on the web page. Certain pages display feed items in two columns, others in groups of three or more. This technique uses WordPress' built-in
fetch_feed functionality to parse external feeds, and a slice of PHP magic to display them in multiple columns. It's flexible too, enabling any number of columns and feed items from anywhere in your theme/template files.
WordPress does an excellent job of keeping track of what's happening with the loop, but once you start customizing parameters and setting up multiple loops, it's a good idea to explicitly reset them using one of three WordPress template tags. In this DigWP post, we'll explore each of these three loop-reset techniques to get a better understanding of when and how to use them in your WordPress themes.
WordPress makes it easy to publish content in any number of categories, with any number of tags, and with any type of custom post format. So for example, in addition to full articles, you could also offer screencasts, links, side posts, tweets, and all sorts of other peripheral content. Complementary material may work great for visitors surfing around your site, but including all of that extra stuff in your RSS feed dilutes the potency of your main articles. The idea here is that your visitors will subscribe to the more focused content.
WordPress provides a variety of functions to redirect logged-in users. So which is best? It really depends on your goals; they're all good methods, it just depends on what you're trying to accomplish.
In this DigWP tutorial, we explain each of these methods along with some useful tips and tricks along the way. These techniques enable you to redirect logged-in users to internal pages, external pages, and even return them to the current page. They're some great tools to have in the ’ol belt. So let's dig in..
One of my other sites, CSS-Tricks, has been around a number of years now. There are nearly 1,400 unique pages of content almost all of which have a comment thread. I had a feeling that in the last four years, despite fairly steady growth in traffic and subscribers, that the number of comments per post has dropped. But how to prove it? I don't know of a way to easily see that data.
Quick WordPress tip for you today! A reader recently asked about displaying the total number of blogroll bookmarks on their site. This sounds simple enough but not everyone meddles with code these days, so here is a nice PHP snippet that will do the job. You can add this code anywhere in your theme template (wherever you want to display the total number of Blogroll links).
Shortcodes are WordPress' way of creating shortcuts for code snippets, strings of text, or anything else that you need to display on your site. So this means that you can save time by replacing your most commonly typed words and phrases with WordPress shortcodes. For example, if you are frequently typing your blog’s URL, you could place the following code your theme’s
In our recent post on pimping the wp-config.php file, we explain that using strong Security Keys is an important part of securing your WordPress installation. In this post, we want to zoom-in on Security Keys and look at what they are, how they work, and how to use them to greatly improve the security of your site.
Easily, the most important file in your WordPress installation is the
wp-config.php file. It serves as your site’s base configuration file, controlling key aspects of WordPress’ functionality and enabling WordPress to do mission-critical stuff like connect to the database. Without
wp-config.php, WordPress simply won’t work. So whenever you install WordPress, one of the first things to do is pimp your
wp-config.php with some custom WP configuration tricks.