Widget output filter – Philip Allfrey http://philip.allfrey.co.nz Web developer & WordPress specialist Tue, 25 Jul 2017 21:29:26 +0000 en-US hourly 1 https://wordpress.org/?v=5.0.2 The Wall http://philip.allfrey.co.nz/2016/01/the-wall/ Fri, 29 Jan 2016 09:10:10 +0000 http://philip.allfrey.co.nz/?p=273 Noel started a strength and conditioning fitness centre, and asked me to set up the website for it. He had chosen the Maniva Fitness theme from Templaza, and needed content added and the theme customised to (…) Read more

The post The Wall appeared first on Philip Allfrey.

]]>
Noel started a strength and conditioning fitness centre, and asked me to set up the website for it. He had chosen the Maniva Fitness theme from Templaza, and needed content added and the theme customised to his branding.

Most of the process was straightforward, but a few elements required extra work. The “Today’s Classes” widget only allowed a single day’s classes to be entered, which was obviously not ideal. I used the Weekly Class Schedule plugin to add an interface for adding classes, instructors and times. Some of these custom post types clashed with those provided by the theme, so I had to unregister the latter for the plugin to work. I then made a copy of the “Today’s Classes” widget which pulled the data for the current days classes from the schedule.

Some other widgets needed minor changes, and rather than making a new copy of each I again employed the widget output filter method of Philip Newcomer which I used for Grey Lynn 2030. I also made some performance improvements by registering a new image size for the classes carousel, so that the full-sized image was not loaded, and deregistering Google Fonts which were included by the theme but not used in the final version of the site.

 

The post The Wall appeared first on Philip Allfrey.

]]>
Philip Allfrey
Grey Lynn 2030 http://philip.allfrey.co.nz/2015/11/grey-lynn-2030/ Fri, 13 Nov 2015 23:22:16 +0000 http://philip.allfrey.co.nz/?p=261 Grey Lynn 2030 wanted to update their WordPress website to a new, more modern, and responsive theme, and incorporate their new branding. They chose the Newspaper6 theme from tagDiv for its appearance and ease of (…) Read more

The post Grey Lynn 2030 appeared first on Philip Allfrey.

]]>
Grey Lynn 2030 wanted to update their WordPress website to a new, more modern, and responsive theme, and incorporate their new branding. They chose the Newspaper6 theme from tagDiv for its appearance and ease of use, and asked me to set it up, with graphic design input from Isla Osborne, who was also responsible for redoing their branding.

Most of the customisation could be done by selecting the relevant options from the the theme’s settings panel, e.g. setting accent colours, choosing predefined page layouts, adding custom css. However there were some things which required me to add functionality. For example the client wanted the large grid on the front page to show a fixed set of pages. While the theme allowed the grid to show pages rather than posts, the only choices for selecting which ones were category, tag or author, and the only choices for controlling the order were sorting alphabetically, randomly, by popularity or by highest rating. To get around this I hooked into the pre_get_posts filter and converted the “highest rating” option to sort by WordPress’s built-in page order instead, ignoring all pages where the order was not set. This allowed me to specify which pages to show, and the order to show them in, simply by setting the page order values to 1,2,3 etc for these pages. Hooking into another filter allowed me to change the  “highest rating” label in the dropdown to “page order” to make it clearer how these pages were being sorted.

The Newspaper6 theme is a very visual one and makes heavy use of featured images. Grey Lynn 2030’s previous theme did not, so I wrote a function which went through and set the first image from each existing post as the featured image. This saved having to do it manually for over 500 posts! I also set  the same to happen for new posts when they were first saved, so that an image would be set even if the post author forgot to. As a final backup I added code to the get_post_metadata filter to get a fallback featured image if the post did not contain any images. To make it easier for the client to change this fallback image I added a setting to the media page which calls the default WordPress media manager window. It was surprisingly tricky to get this integrated – Shiba’s tutorial was the most helpful, though even this did not fully explain how to set the modal_update_href parameter.

Grey Lynn 2030 have a large number of categories on their website, and they wanted the sidebar widgets to show recent posts or recent comments only for the current category. While there are plugins providing widgets which do this if you are viewing a Category, they don’t work if you are on a Page which includes posts via a secondary query, which was the situation here. I was able to restrict the built-in Recent Posts and Recent Comments widgets to the desired category by hooking in to the widget_posts_args and widget_comments_args filters and setting the category argument based on that specified in the meta values for the current page. I also wanted to add dates to the recent comments widget, which turned out to be tricky as it doesn’t have any means of filtering its output. To get around this I used the ingenious method of Philip Newcomer which adds a filter to the output of any widget.

The post Grey Lynn 2030 appeared first on Philip Allfrey.

]]>
Philip Allfrey