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.

Tagged: 

Multiple Post Grids

  • Creator
    Topic
  • #5845
    timworx
    Participant

    I’m running into a little glitch, or at least it is appearing as one.
    I’m trying to run multiple post grids on a page with one being offset. I.e. the first has 3 posts (displayed larger) and the second continues from the same category. So it should be offset by three.
    When I set offset to “3” I receive the error “Apologies, but there are no posts to display.”

    There are 6 posts available, though, and they will all appear if I don’t set the offset. So, I’m not sure what’s going on there.
    Is it something I’m doing?

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

    Hello,

    Can you show me more specifically what you’re doing? Are these uses of the [post_grid] shortcode in a page? If so, can you show me exactly what you’ve got the for usages? Or are these with a custom layout?

    If you are finding some kind of a bug, I’d like to be able to reproduce it and definitely figure out a fix.

    #5868
    timworx
    Participant

    Certainly! Also, I must applaud you, you consistently have some of the best support around. There is nothing worse then needing support in the first place, and then getting set back waiting for days for response. Keep it up!

    I am indeed using the shortcode. As an aside, everything is its latest version, also.

    This is my current code:

    [post_grid columns="3" rows="1" categories="our-work" orderby="date" order="DESC" offset="0"  link="false" link_target="_self"]
    [post_grid columns="4" rows="4" categories="our-work" orderby="date" order="DESC" offset="2" link="false" link_target="_self"]

    New let me explain the results of tweaks and what I hope to accomplish, too.

    I want one row of 3 across, then below that I want the rest of the posts from that category displayed in, the smaller, 4 across (for however many columns I define)

    So, if I first set up my 3 across. 1 row, 3 col

    [post_grid columns="3" rows="1" categories="our-work" orderby="date" order="DESC" offset="0"  link="false" link_target="_self"]

    So far so good. But for the second loop (displayed 4 across) I want to pick up where the first loop left off. Therein lies my dilemma. With NO offset, it starts again from the first post as I should expect, of course. It gets a little unpredictable after that though.

    With an offset of 1:

    [post_grid columns="4" rows="4" categories="our-work" orderby="date" order="DESC" offset="1" link="false" link_target="_self"]

    It skips the first two posts, and starts with the 3rd post (in date order). Not sure why, however, it’s close!
    Next I tried the offset of 2:

    [post_grid columns="4" rows="4" categories="our-work" orderby="date" order="DESC" offset="2" link="false" link_target="_self"]

    This now starts with the loop with the 5th post. My workaround was to create a “filler”, which acted as the 4th post, the one that winds up disappearing (the first loop shows the first 3, the second loop has to start as either the 3rd or 5th post, but I need it to start at the 4th)

    I tried play with custom query args as well, but I’m not entirely sure how it uses the arg so I don’t think I was formatting them correctly. I did see that it uses “get_posts”
    I tried:

    [post_grid columns="4" rows="3" order="DESC" query="array( 'category' => 8, 'offset' => 3 )" link="false" link_target="_self"]

    But no luck, it started form the first and stopped displaying after the 5th. Although I’m not sure why.

    Am I doing something wrong? Any thoughts on how to remedy this? The current use is a portfolio, not a major ordeal if I have to keep adjusting the date on the “filler” post that gets cut off so it’s always the fourth. However, I could definitely see myself using that functionality in a magazine/newspaper site or other.

    Trust me, I plan to get plenty of use out of your awesome framework.
    Thank you!!

    #5871
    timworx
    Participant

    Problem solved, for the most part. I figured out (from another thread) how to properly format the query for this.
    It works perfectly with the second loop querty set to cat=8&offset=3

    Any idea why the not-so-manual route wasn’t working? No wp_reset_query(); or something?

    One last thing for now, I promise. Is there anyway to make, say, specific content-grid.php templates, or have multiple grid templates, rather? For some I want to display it without links to the posts themselves, for a simple portfolio.

    #5873
    timworx
    Participant

    Edit: Figured out how to apply a specific grid template. Used:

    function portfolio_grid_template( $parts ) {
    	if (is_page(66))
    		$parts['grid'] = 'portfolio';
    	return $parts;
    }
    add_filter( 'themeblvd_template_parts', 'portfolio_grid_template' );

    I love this Framework. The documentation is quite good too. Isn’t your framework, at least v2, fairly new? That makes good documentation even more amazing.

    #5884
    Jason Bobich
    Keymaster

    I’m looking through all this and can confirm everything you’re saying. It’s a bit complicated, but this is something I’ve actually already inadvertently fixed a few weeks ago for the next upcoming update to the framework (ahich will be framework v2.2.1, Jump Start v1.0.1). So, in other words, what you’re describing is indeed a bug!

    What’s the bug? — With the [post_list] and [post_grid] shortcode the user can query of series of posts with these options I’m giving them. These two shortcodes use the same function internally. However, internally, WordPress will not allow you to have a query where you combine offset and an unlimited number of posts. So, for example you can’t have a query like: numperposts=-1&offset=2 — This will always just simply return all of the posts with no offset. So, I wanted to allow the user to be able to still do something like this:

    [post_list numberposts="-1" offset="2"]

    And so the way this is possible is I query the posts, then look for you inputting the “numberposts” parameter, and then manually remove the posts from the start you want to offset. Well, what I didn’t take into account was the fact that the [post_grid] shortcode doesn’t allow you to pass in a “numberposts” parameter because it figures it out for you (columns*rows). So, you say 4 rows by 4 columns, the framework passed in a numberposts as 16, and the offset is successful by WordPress. Then, after the query, the framework looks at the default “numberposts” the function has always set to -1 (not being used with [post_grid]) and then pops off more posts to manually apply the offset. — So in other words, if your offset is 2, it will end up being 4, with some other strange results mixed in there depending on different factors.

    What’s the workaround? — Simply use the custom “query” string perameter. When you do this, the framework’s function skips over a whole bunch of stuff, and basically just puts the query in your hands.

    #5896
    timworx
    Participant

    After saying I had it fixed, I soon realized that you couldn’t have the offset and unlimited posts. hah. So you predicted my next run-in. For now, setting the posts_per_page to a very high number solves the issue.

    Strangely, I tested paginated grid posts in the layout builder and for some reason wound up with them as full-width (as if permanently stuck to 100%).
    In the css there is no <div class="grid-item column grid_3">
    <div class="article-wrap">
    like the regular grid_row has. I’m using the stretch child theme as a base, if that helps narrow anything down.

    It goes straight from grid_row to article. You can see it here.

    #5911
    Jason Bobich
    Keymaster

    Are you sure you haven’t made edits to content-grid.php from your Child theme? This is where that HTML markup comes from that wraps the individual items in the grid.

    #5923
    timworx
    Participant

    No, I definitely haven’t. I did do edits on a new custom content template for grids on another page. However, the regular ones are displaying fine, it’s just the paginated. You can see the shortcoded grid_posts (the layout builder grid_posts, non paginated, works fine too) working properly here.

    I also compared my grid files to that of another child theme, all checks out.

    #5929
    Jason Bobich
    Keymaster

    This isn’t an issue anyone else has reported and if paginated post grids in general just didn’t display, that’d be a big issue many people would be running into. But I’m, definitely double checking thoroughly on my end, and unless I’m missing something obvious, I cannot see how the issue you’re describing is possible.

    Paginated post grid from layout builder: http://www.themeblvd.com/demo/jumpstart/features/layout-builder/sample-layouts/classic-magazine-1/

    Paginated post grid from page template: http://www.themeblvd.com/demo/jumpstart/page-templates/post-grid-3-columns/

    I can only think that’s there’s something unique on your end. It just doesn’t make sense that you would have the wrapping div around the <article> on the non-paginated post grid, but not on the paginated post grid, when Jump Start (by default) uses the same template part file for both places.

    Is it possible you’ve been playing with the themeblvd_template_parts filter?

    #5930
    Jason Bobich
    Keymaster

    All right, so I’m looking at your site more closely now. You must have made customizations in this regard with how the post grids are displayed. On your paginated post grid it looks like you have a different design for the posts then over on the page where you’re using the [post_grid] shortcodes. So, is it possible you setup a different template part file for the paginated post grids? It seems like you had to have done this.

    #5978
    timworx
    Participant

    Yeah, it’s rather odd indeed. Here’s what I found. I have this code in place to modify the grid on one page:

    function my_template_parts( $parts ) {
    	if (is_page(66)) {
        $parts['grid'] = 'portfolio';
        return $parts;
    }}
    add_filter( 'themeblvd_template_parts', 'my_template_parts' );

    and it works perfect, everything displays fine, it’s the “Our Work” page. The only difference is that the “Read More” button is removed and the title isn’t hyperlinked.

    The interesting part is that even if you have the same exact code in my custom content-portfolio.php file as content-grid.php, it breaks the layout, like here. So, first bare in mind that the custom template should not be applying to this page and ONLY be applying to id 66, or the Our Work page.

    But, assuming that code is somehow messed up and applying to all pages with the grid, it still breaks it even when the “custom” template has the same content as the original grid template. This isn’t something that I really need to deal with right now, however, I plan to extensively use the framework and could certainly see it becoming a conundrum.

    Any clues?

    #6016
    Jason Bobich
    Keymaster

    I think that this may all be coming from trying to use conditionals within your my_template_parts function. When you’re dealing with a paginated post grid, you now have the main query being modified. So is_page(66) will no longer work how you’re expecting.

    Come over to this topic. I think this is your answer: http://support.themeblvd.com/forums/topic/post-grid-conditional-tag/#post-6015

    #6121
    timworx
    Participant

    Hmm, not quite. It really is a peculiar situation.
    I’m not having trouble with query correct data, at this point, I’m having display issues.

    Here’s my code:

    function portfolio_set_global_post_id(){
    	global $portfolio_post_id;
    	$portfolio_post_id = get_the_ID();
    }
    add_action( 'wp', 'portfolio_set_global_post_id' );
    
    // Modify the template that displays post grids for the portfolio page only 
    function portfolio_template_grid( $parts ) {
    	global $portfolio_post_id;
    	if ($portfolio_post_id == 66) {
        $parts['grid'] = 'portfolio';
        return $parts;
    }}
    add_filter( 'themeblvd_template_parts', 'portfolio_template_grid' );

    This is ID 66.
    Currently, I have the same code in my custom grid template (content-portfolio.php) as the content-grid.php page.

    It is doing exactly what it’s supposed to be doing, working perfectly on the page that it is supposed to be working on. BUT it is breaking both regular and paginated grid posts on any other page.

    A page with the regular grid post is missing the <div class="grid-item column grid_4"><div class="article-wrap"> wrap, it’s going straight to <article>. It’s also displaying the tags. So, it appears to be using “single” or content.php as the template.

    Here is where it gets confusing for me, but may be the giveaway for you:
    If I comment out add_filter( 'themeblvd_template_parts', 'portfolio_template_grid' ); to deactivate the custom template, the paginated posts now work! Even though the custom grid template and framework content-grid.php have the exact same code.

    I’m a roll with breaking things, got a wrecking ball for me?

    #6125
    Jason Bobich
    Keymaster

    The problem is with how you’re structuring your function. I originally thought you just made a typo and that’s why I fixed your code last week when you posted it as not to confuse others (see this post).

    When you add a filter, you’re adjusting that value every where that filter is applied. So, every time you add a filter, you need to make sure and always return the value, whether you’ve changed it not. In your function, what you’re essentially doing is breaking the template part filter on every page that is not 66, because you’ve wrapped your return statement in your IF statement condition. By messing this up and just making the template part null in general, you’re basically making it so every template part in every scenario of the framework (except page 66) is going to pull content.php.

    What you’re trying to do should look more like this:

    function portfolio_template_grid( $parts ) {
    	
    	global $portfolio_post_id;
    	
    	// If this is page 66, modify the grid part
    	if( $portfolio_post_id == 66 )
    		$parts['grid'] = 'portfolio';
        
    	 // Always return $parts, whether you modified it not!
    	return $parts;
        
    }
    add_filter( 'themeblvd_template_parts', 'portfolio_template_grid' );
    #6183
    timworx
    Participant

    Pure genius.

    I figured it was causing me to break it, I just couldn’t figure out why or how.

    Once again, you’re the man. This framework is seriously going places.

Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.