This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Tip: simulate post grid (for specific pages)

  • Creator
    Topic
  • #981
    mharpen
    Participant

    I spent a bit of time trying different options, and wanted to share this… I wanted to add something similar to a 2 column post grid, but only for 2 pages (and 1 row). Basically I wanted to show: the feature image, the page header and a button to point to the page. These look nice in any page.

    I don’t uses posts on my site, so I wanted something similar to a post grid, that would point to a couple of “pages”, not “posts”. The theme’s post grid opitons are really nice, but they only work well with posts. For example you can do some nice selection options with posts, such as show only certain categories, or posts with certain tags. But for pages, you don’t have those options.

    The easiest way I found, is by using the TB shortcodes (see 2nd image below). I know this may seem obvious, but I spent hours trying to use the Layout builder’s “Columns” element with raw content and shortcodes, and I also tried using the Post Grid element and changing the Query Search to show 2 pages, but couldn’t find any way to do that.

    With the various, nice post grid options in the theme, I felt there had to be a way to easily show pages (with the page’s featured image and title) in a nice grid. But I couldn’t find any way to do so.

    Jason, It would be really cool if there was a shortcode to create a “page grid”, and specify the # of columns, # of rows, and which pages to show (using comma delimited list of slugs or page ID’s). In your free time of course. 🙂

    Hope the images help someone else who might want to do the same thing. A grid that points to pages looks nice on a home page, and helps direct people to selected pages.

    Example result of grid of 2 pages:
    http://picturestack.com/227/299/lSPthemesuggpN3K.jpg

    Editor window showing shortcodes and inserted media and header text to create the grid.
    http://picturestack.com/227/82/mlrthemesuggpqoB.jpg

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #985
    Jason Bobich
    Keymaster

    This is sort of tough to do from the custom query option because in all ways (that I know of anyway) to specify specific pages would not be possible within a single string.

    I can think of two ways where actually feeding pages through to the post grid would be possible the way things are setup.

    1) Take the pages you want to be in the post grid and set them as Child pages to some Parent page. Then in your custom query string you’d do this:

    post_type=page&post_parent=123&numberposts=2

    Where “123” is the numerical post ID for the Parent page, to which you want the child pages below it to show. Note that by using the custom query string in any post grid, you’re overriding the number of posts normally generated for you based on the columns/rows. So, you need to specify that, as well.

    Reference: http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters

    2) Now, this is super hacky, but an interesting thing I just thought of. Internally, there is a filter on the query string every time a post grid is generated. But there’s no way to really identify this filter with a specific post grid instance.

    In your instance of the Post grid, you could use the “query” option to pass in some unique identifier to use as a “catch” from your PHP function that you’re going to attach to the filter for all post grid queries.

    So, for example, setup a post grid and for the query option write something like:

    my_unique_key

    Now from your Child theme’s functions.php you can filter onto the query string for all post grids and use that identifier to trigger some custom query string.

    /**
     * Custom query for post lists/post grids
     */
    function my_custom_posts_query( $query, $args ){
    	if( $args['query'] == 'my_unique_key' ){
    		$query = array( 
    			'post_type' => 'page', 
    			'post__in' => array( 1, 2, 3, 4 ) // ID's for any pages you want to include
    		);
    	}
    	return $query;
    }
    add_filter( 'themeblvd_posts_args', 'my_custom_posts_query', 10, 2 );
    #992
    mharpen
    Participant

    Both of those are awesome word-arounds!! Thank you J!
    I was so close to the first one you provided. But I didn’t think of the the post_parent paramenter and using child pages. I looked into a plugin that allows exposing the “category” for pages in the admin, and then using the cat parameter. But I decided not to go that route, since it sounds a little risky messing with pages in the admin like that.

    I like your second example a lot too. Thanks for taking the time to show me that option. That allows building the array of page_id’s which as you said, can’t be done in the basic query string.

    Maybe you could give some thought to how you might be able to incorporate your 2nd suggestion in your themes and provide a new shortcode that would work with that function. Again, in your spare time of course 🙂

    Theme Blvd ROCKS!

    #996
    mharpen
    Participant

    Jason, is there an option in the post grid shortcode to “not” show the text excerpt (just the title, feature image and button)? If not is there a way to hide it for just a particular post grid? Thanks a ton! I’ve looked but can’t find a way.

    #997
    Jason Bobich
    Keymaster

    is there an option in the post grid shortcode to “not” show the text excerpt (just the title, feature image and button)?

    I’m afraid not. — This is because the post grids are a core part of the framework and the “design” of the post grid can be different in every theme. It’s setup with the file content-grid.php and every theme could theoretically contain different markup in this file.

    So, for example, if the [post_grid] shortcode had some sort of option to hide the excerpt, it means I’d have to make sure every theme I made had an excerpt in the design of the post grid. An example of a theme where this wouldn’t work would be Swagger. I try not go overboard on these options so every theme doesn’t end up looking identical.

    You could target your post grid by copying content-grid.php to your Child theme and then using some sort of conditional tags to show or hide different elements similarly with how you’ll see I did with the global theme options currently in the file.

    http://codex.wordpress.org/Conditional_Tags

    #999
    mharpen
    Participant

    I just remembered the option you have in Theme Options > Content tab > “Show or Hide Exceprts”. Actually, for me at least I’m fine with not having “any” excerpts showing. So this works pretty good for me, along with your idea to use the Parent Page. I can get what I want. Just wish there was a way to select pages by ID in the Post Grid short code. I’ll look into using the function you provided above as the second option. Your post grids are really sweet. I really like the frame around the photos. And did I mention, I like your choice of sample photos in your themes. The women and landscapes are beautiful!

    #1006
    mharpen
    Participant

    I’ve modified your function (placed in the child theme functions.php) to allow passing a list of page or post ID’s in the query string of the post_grid shortcode. See example in comment:

    /**
     * Custom query for post lists/post grids
     * Example shortcode to use: [post_grid query="show_ids=31,43" columns="2"]
     */
    function my_custom_posts_query( $query, $args ){
    	$lc1 = strstr($query, "show_ids=");
    	if($lc1 != false) {
    		$lc1 = strtok($lc1, "=");	
    		$lc1 = strtok("&");	
    		if($lc1 != false) {
    			$query = array( 
    				'post_type' => 'page', 
    				'post__in' => explode(",", $lc1)
    			);
    		}
    	}
    	return $query;
    }
    add_filter( 'themeblvd_posts_args', 'my_custom_posts_query', 10, 2 );
Viewing 6 replies - 1 through 6 (of 6 total)
  • The forum ‘Alyeska Responsive WordPress Theme’ is closed to new topics and replies.