JetPack Tiled Gallery fix

Community Forums Forums Design Tips and Tricks JetPack Tiled Gallery fix

This topic is: not resolved

This topic contains 9 replies, has 6 voices, and was last updated by  designbytracy 1 year, 3 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #9934

    acekin
    Participant
    Post count: 9

    I use the Crystal Child Theme on my site, keptlight.com. Recently an update to JetPack plugin offered a new way of presenting galleries called tiled gallery. I tested it and found that the presentation did not fill the entire width of the content area and filed a bug report with the plugin. The developer recommended that I try adding the following to the functions.php and it worked. This is a workaround until the fix may make its way to the theme update. By the way, there is another small bug I reported which deals with the slideshow presentation anomaly. You can see it in the second slide in the slideshow, the right border almost disappears. That will be fixed in the next JetPack update.

    if ( ! isset( $content_width ) )
    $content_width = 640;

    I disabled this code segment so that you can see the gallery presentation:
    http://www.keptlight.com/2013/01/test-tiled-galleries/

    #13273

    Stefano Dotta
    Participant
    Post count: 4

    Hello Cemal,

    I actually ran into the same issue a few days ago, when I started playing with the new tiled gallery from the Jetpack.

    After some digging in the php files of the Jetpack plugin, I came across this function that defines the tiled gallery width to be used by default, if the variable $content_with is not defined or empty: (/wp-content/plugins/jetpack/modules/tiled-gallery/tiled-gallery.php)

    public static function get_content_width() {
    global $content_width;

    $tiled_gallery_content_width = $content_width;

    if ( ! $tiled_gallery_content_width )
    $tiled_gallery_content_width = 500;

    return apply_filters( ’tiled_gallery_content_width’, $tiled_gallery_content_width );
    }

    The theme I use on my site (News) defines a $content_with of 580px, according to this line found in the functions.php of the theme:
    $content_width = apply_filters( ‘content_width’, 580, 430, 910 );

    Not sure where and when the  two other values are used, but 910px it’s actually the width of my content when I use a full page width, according to Firebug.

    BTW, I have created  a custom post type to display my galleries, following the tutorial provided by Brian from StudioPress.

    I therefore “hard coded” the variable  in my single-portfolio.php file and my galleries are now taking the whole page width.
    $content_width=910;

    Not sure it follows the best practices in term of coding, but it works…
    http://www.twoswisshikers.net/portfolio/jura-en-hiver/ (in French only)

    And by the way, on all other pages or posts, the content width is reverted back to 580px, I guess taking the value defined in the functions.php file.

    Question:
    Can somebody explain the purpose of the three content_width values defined in the functions.php file and how to use them in order to avoid doing any hard-coding?

    Many thanks in advance,


    Stefano, an avid hiker from Switzerland.
    http://www.twoswisshikers.net/

    #13279

    Bill Murray
    Participant
    Post count: 575

    I haven’t looked at the code, but from what I’ve read, $content_width is not technically width of the content. It’s the width of embedded content such as images or videos. The 3 values represent that width when 1,2 or 0 sidebars are displaying.

    I therefore “hard coded” the variable in my single-portfolio.php file and my galleries are now taking the whole page width.
    $content_width=910;

    This makes perfect sense in light of the way $content_width works. If your single-portfolio.php also displays a sidebar, that might be too wide though.

    For $content_width and mobile responsive issues, this might be helpful.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #13301

    Stefano Dotta
    Participant
    Post count: 4

    Bill,

    Thank you for your answer and the link provided.

    Actually the single-portfolio.php is a full-width page and has no sidebars.

    Regards,


    Stefano, an avid hiker from Switzerland.
    http://www.twoswisshikers.net/

    #19703

    ameeker
    Participant
    Post count: 29

    I had this same question today, except using the Executive theme, and with the intent to use a tiled gallery in a widget in an area that is full width on the home page. When I asked over at the WP forums, they suggested I look to the TwentyTwelve theme for direction on how to filter the content width per page template, which I tried using this below, but it didn’t work (used in the functions file, and took out a || ! is_active_sidebar( ‘sidebar-1′ ) along the way in the original example here: http://core.trac.wordpress.org/browser/trunk/wp-content/themes/twentytwelve/functions.php#L414).

    `

    /**
    * Adjusts content_width value for full-width and single image attachment
    * templates, and when there are no active widgets in the sidebar.
    *
    * @since Twenty Twelve 1.0
    */
    function twentytwelve_content_width() {
    if ( is_page_template( ‘page-templates/home.php’ ) || is_attachment() ) {
    global $content_width;
    $content_width = 1140;
    }
    }
    add_action( ‘template_redirect’, ‘twentytwelve_content_width’ );`

     

    Any thoughts about how to get that to work?

    #48281

    Cyndy Otty
    Participant
    Post count: 11

    Resurrecting this thread because I’m kind of baffled by the tiled galleries and content width thing. Basically, my experience with all of the StudioPress themes I’ve used is that the tiled galleries always load as if the sidebar is present even in the full width layout.

    Does anyone know how to fix that? Looks like ameeker was trying but, like me, is stuck with how to take the code from Twenty Twelve and incorporate it.


    — Cyndy Otty —
    http://gentlewit.com

    #48330

    Bill Murray
    Participant
    Post count: 575

    There are several different ways to fix this. Rather than discuss Genesis child themes generally, is there one where you have this problem? Do you have a specific URL where you have a tiled gallery?

    First, re-read my previous post on what $content_width means. It is the width of the embedded content when 1, 2, or 0 sidebars are present, in that order.

    You can set the $content_width with a filter. A previous post in this thread includes that code. You can also just hard code it in a page template. You can also do it with a conditional. This is what @ameeker‘s code attempts to do. However, her conditional isn’t right for a typical Genesis theme. In effect, her conditional says “if the current template is home.php in the page-templates folder, then do this stuff.” However, while the page-templates folder exists in the TwentyTwelve theme, it doesn’t exist for a typical Genesis child theme. Therefore, the if part of her conditional will never be satisfied, so the code in the then part of the conditional will never be executed. That’s 1 reason why her code won’t work.

    Of the different ways to fix this, the easiest to implement in general is to set a filter with this code:

    $content_width = apply_filters( ‘content_width’, 580, 430, 910 );

    Note: the forum software sometimes changes quotes. Be sure that the single quote surrounding content_width is going straight up and down.

    You can put that code in your child theme’s functions.php. You would replace 580 with the $content_width you’d like your site to use when 1 sidebar is used; replace 430 with the width when 2 sidebars are used, and replace 910 with the width when 0 sidebars are used (that is, the page is full width). Genesis should take care of the rest.

    The other options I discussed could be useful when you need even more flexibility, such as a case where you have a special page with 1 sidebar, but the sidebar is not the standard width, so the 580 value does not apply.

    Hope that helps.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    #48354

    Cyndy Otty
    Participant
    Post count: 11

    Thanks, Bill, that was extremely helpful! :-)


    — Cyndy Otty —
    http://gentlewit.com

    #50542

    ameeker
    Participant
    Post count: 29

    Just wanted to confirm that was Bill said worked. HE knows that, of course, but thanks!

    #55939

    designbytracy
    Participant
    Post count: 51

    Success for me too on this. Thanks!


Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.