A (Better) Genesis Featured Page Widget

A (Better) Genesis Featured Page Widget

Early this year, Genesis Super Hero Developer Bill Erickson wrote a post called “Don’t use the Genesis Blog Page Template”, which made a pretty compelling argument for, well, not using the Genesis Blog Page Template. I may have been alone on this, but it took me by surprise, as I thought that was the way to set up a WordPress site.

It turns out that I was wrong. If your site has a blog, or posts, page which is not the Front Page (official term), then Bill recommends setting it up the WordPress Way (emphasis mine), which is to say, in your Settings > Reading options, you select a Static Front Page and a Posts Page. WordPress automagically handles the output of the Posts Page, and there’s your blog!

This is probably important to do, even if you take the standard Genesis approach of using a widgetized Front Page. One win on this (beyond Bill’s point about setting queries) is that you can write up your Front Page content, appropriate for search engines and humans alike, and even if it doesn’t show, search engines see it and can help humans find you and your site. So, since then, I’ve happily been setting up all my new sites (both mine and clients’) with a static Front Page, unless they truly are a straight up blogger.

It’s been an easy and painless transition.

Until.

I’m helping a friend set up a site for a community theater group in which she is actively involved. Basically, I installed WordPress, did my standard configuration, including the static Front Page, and sent her off to do her worst. All went swimmingly until she used the Genesis Featured Page widget to show her Posts Page…and it didn’t. It didn’t show the Posts Page title, or the featured image. Interestingly, it showed the content from the posts–all of them. It kind of looked like this (not her site, but mine):

Genesis Featured Page Widget Behaving Badly
So, the Featured Page widget was behaving like the Featured Posts widget, which was not at all what she wanted, and trying to explain why it was behaving that way was just confusing us both.

There are a couple of ways to get around it, neither of which are great, to my mind. A friend who encountered this on a site he was building ended up doing a text widget to hand code it–looks great, and no one knows the difference, but not easy for the end user to change. As for us, we got around the issue temporarily by (gasp!) using the Genesis Blog Page Template, but that’s not the WordPress Way. Also, it bothered me and I decided I would try to figure out why it wasn’t working. It turns out that it’s a function of how WordPress works, not something necessarily specific to the Genesis Framework. Next step: see if it is possible to make it work.

Short answer: yes, it’s possible to make it work.

If you’re a skip to the end kind of person, and just want to know how to make the Genesis Featured Page widget work with your static Front Page site, the answer is in this plugin I’ve written. Creatively called “(Better) Genesis Featured Page Widget”, you can download it from GitHub.

Long answer: once you designate a Posts Page, WordPress treats it totally differently than any other page you’ve created. The title and content of the Posts Page do not show. According to WordPress, even if you give the Posts Page an amazing title and slam dunk content, it’s almost as if those items don’t exist. The posts themselves become the content. Standard conditional tags such as is_singular( 'page' ) won’t work on this page–according to WordPress, it is no longer a page. However, if you retrieve the Posts Page using get_option( 'page_for_posts' ), you can begin to work with it as if it were a page, within certain limitations.

This won’t be submitted as an official WordPress plugin, as I am hopeful that it will be addressed in Genesis itself in a future release. But for now, if you need it, it’s here.

How the (Better) Genesis Featured Page Widget Works

Some details:

  • This is a replacement for the existing Genesis Featured Page widget. Visually, almost nothing in the widget setup will change.
  • Almost nothing, but one change will be that all registered image sizes will be available for the widget to use. The standard widget uses the thumbnail size, and additionally registered sizes (registered by your theme or a plugin); the new widget will also allow you to use the medium and/or large image sizes (StudioPress, please add this to the standard widgets!). But don’t be ridiculous and use a large image when the medium will do. Self control, friends.
  • How the widget handles pages other than your Posts Page will be unchanged. The only output changes occur if you have selected the Posts Page in the widget.

Because of the interesting way WordPress handles the Posts Page, the new widget’s output needs a bit of explaining. First, no matter what, the widget will use the Posts Page featured image. If you don’t set a featured image for that page, no image will show. Secondly, the page title and content will behave in one of two ways:

If the Posts Page has no content of its own, which is pretty standard since most themes don’t show it anyway, the widget will output the title and content from the most recent post. This is because of how WordPress views this page and its content–which is to say, it has no content of its own, outside of the posts. With this option, the widget actually blends the behavior of the Featured Page widget and the Featured Posts widget.

Featured Page Widget Showing the Latest Post
Featured Page Widget Showing the Latest Post

If the Posts Page has content of its own, even if it doesn’t display on your site, the widget will use the Posts Page title and content for its output. At this point, the widget will behave just as the Featured Page widget does with any other page.
Featured Page Widget Showing the Posts Page Content
Featured Page Widget Showing the Posts Page Content

Of course, just as with any other page, you can choose to show just the image, with or without the title, with the full content or limited.

Show the Blog Page Content On Your Site

If you are the kind of person who wants the Posts Page to have content on the front end of the site, above the posts–like a blog intro paragraph, you can create a home.php file with this content and upload it to your theme:

<?php
/**
* Blog Intro
*
*/
remove_action( 'genesis_before_loop', 'genesis_do_posts_page_heading' );
add_action( 'genesis_before_loop', 'rgc_blog_intro' );
function rgc_blog_intro() {
$posts_page = get_option( 'page_for_posts' );
if ( is_null( $posts_page ) ) {
return;
}
$title = get_post( $posts_page )->post_title;
$content = get_post( $posts_page )->post_content;
$title_output = $content_output = '';
if ( $title ) {
$title_output = sprintf( '<h1 class="archive-title">%s</h1>', $title );
}
if ( $content ) {
$content_output = wpautop( $content );
}
if ( $title || $content ) {
printf( '<div class="archive-description">%s</div>', $title_output . $content_output );
}
}
genesis();
view raw home.php hosted with ❤ by GitHub

It took me six months of setting up sites this way for me to encounter this issue, so I’m curious. Am I alone? Have you run into this? How have you resolved it? Or have you? And if you download the plugin from GitHub, and it helps you, I’d love to hear about it.

If you stuck with me all the way to the end, here’s the download link again: “(Better) Genesis Featured Page Widget”

Do something awesome. Tell a friend:

subscribe by email

If you're an email kind of person, that's totally cool. Go ahead and sign up here to get the latest blog entries in your inbox! No worries, I never share your address.
  • This field is for validation purposes and should be left unchanged.

Reader Interactions

Comments

  1. December 2, 2014

    Thanks Robin – I was pulling my hair out for hours trying to figure out why the widget doesn’t work with the Posts page. I am using the Genesis Sandbox Featured Page version as that has the option to use the excerpt field too. Decided it would just be quicker to make a text widget that looks exactly the same in this case though. Not ideal, but a real timesaver!

    • December 2, 2014

      A lot of people haven’t encountered this issue, I think, but as more people opt to use a static front page, I think they will. If you’ve got the know how to do a text widget, that is definitely an easy option, but I wanted to see if the problem could be resolved so that clients could (for example) change the featured image on the blog page for themselves. If that’s not a consideration, though, a text widget definitely can do the trick.

      I’ve heard good things about the Sandbox widget but haven’t used it myself. Cheers!

  2. December 31, 2014

    Hi Robin,

    Great tutorial! I was wondering why the Genesis featured page widget does not show the pages created in portfolio. Do you know a way to get them to show in the featured page widget?

    Happy New Year!

    L

  3. March 7, 2015

    Hi there,
    I wonder if you know a work around for the issue that i’m having. Even with the Better Featured Page Widget, my home page is showing 3 copies of my thumbnail. I’ve come to the conclusion that this is being caused by the settings for my Blog page; where it is set to show 3 posts per page. If I change this to 1 I then have one post on my blog page which is not what I want at all. Any ideas?

    Thanks

    • March 7, 2015

      Hmmm, that is definitely not what you want to happen. Can you tell me what settings you have on the widget, especially the content settings (full content, excerpt, content limit)? Otherwise, I would have to see the site to get an idea of what might be happening. Is there any content on the blog page itself, or is it just showing the posts? If you don’t want to share the link here, shoot me an email and I’d be happy to look at it.

      • March 7, 2015

        On a second look, I didn’t have your plugin installed (face smack), however, now that I do, I can see that it doesn’t have an option for pages at all. Thank you for your speedy reply though!

          • March 7, 2015

            Not quite, but I can live with it as is for another few hours. lol. I wound up adding my HTML to text boxes versus using any of the other plugins and linking to my pages. I added my link so you can see what I mean.

          • March 7, 2015

            Glad you got a solution in place that worked for you! Sorry the plugin was not helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Bars Code Check chevron-down chevron-left chevron-right chevron-up Envelope Laptop Search Times Facebook GitHub Google Plus Instagram LinkedIn Pinterest Twitter WordPress Logo Wordpress Simple