Community Forums › Forums › Archived Forums › Design Tips and Tricks › JetPack Tiled Gallery fix
Tagged: jetpack, tiled gallery
- This topic has 9 replies, 6 voices, and was last updated 11 years, 6 months ago by
designbytracy.
-
AuthorPosts
-
January 6, 2013 at 10:17 am #9934
ACEkin
ParticipantI 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/January 20, 2013 at 9:08 am #13273Stefano Dotta
MemberHello 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/January 20, 2013 at 9:58 am #13279Bill Murray
MemberI 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.
January 20, 2013 at 12:38 pm #13301Stefano Dotta
MemberBill,
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/February 11, 2013 at 4:05 pm #19703ameeker
MemberI 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?
Looking for Genesis website design backed by strategy? http://www.angiemeekerdesigns.com
June 28, 2013 at 3:41 pm #48281Cyndy Otty
MemberResurrecting 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.comJune 28, 2013 at 10:09 pm #48330Bill Murray
MemberThere 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.
June 29, 2013 at 6:11 am #48354Cyndy Otty
MemberJuly 13, 2013 at 9:03 am #50542ameeker
MemberJust wanted to confirm that was Bill said worked. HE knows that, of course, but thanks!
Looking for Genesis website design backed by strategy? http://www.angiemeekerdesigns.com
August 12, 2013 at 8:06 pm #55939designbytracy
Participant -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.