{"id":130040,"date":"2014-06-25T08:30:00","date_gmt":"2014-06-25T12:30:00","guid":{"rendered":"http:\/\/premium.wpmudev.org\/blog\/?p=130040"},"modified":"2017-10-20T01:07:15","modified_gmt":"2017-10-20T01:07:15","slug":"how-to-go-horizontal-with-your-wordpress-content","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/how-to-go-horizontal-with-your-wordpress-content\/","title":{"rendered":"How To Go Horizontal With Your WordPress Content"},"content":{"rendered":"<p>It&#8217;s a curious thing but whilst WordPress themes largely continue to revolve around the tried and trusted methods of delivering content and a reading experience, it&#8217;s the app makers that are pushing the boundaries.<\/p>\n<p>Horizontal scrolling as an approach is pretty much shunned by WordPress theme developers, and yet is being embraced as a storytelling technique particularly on tablets.<\/p>\n<p>In this post, we&#8217;ll cover:<\/p>\n<ul>\n<li><a href=\"#horizontal-wordpress-content\">Horizontal Scrolling WordPress Content<\/a><\/li>\n<li><a href=\"#make-content-horizontal\">Making Content Horizontal<\/a><\/li>\n<li><a href=\"#get-horizontal\">Getting Horizontal With display:table-cell<\/a><\/li>\n<li><a href=\"#test-content\">Walking Through The Test Content<\/a>\n<ul>\n<li><a href=\"#simple-text-page\">The Simple Text Page<\/a><\/li>\n<li><a href=\"#full-screen-image\">Full-screen Image With Text Overlay<\/a><\/li>\n<li><a href=\"#half-page-image-left\">Half-Page Image Left<\/a><\/li>\n<li><a href=\"#half-page-image-right\">Half-Page Image Right<\/a><\/li>\n<li><a href=\"#full-page-image\">Full-Page Image, Opaque Text Overlay<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#add-horizontal-mix\">Adding Horizontal To Your Mix<\/a><\/li>\n<\/ul>\n<h2 id=\"horizontal-wordpress-content\">Horizontal Scrolling WordPress Content<\/h2>\n<p>So, let&#8217;s take a leaf out of the tablet and look at how to bring horizontal scrolling content to your WordPress content.<\/p>\n<figure id=\"attachment_130254\" class=\"wp-caption aligncenter\" data-caption=\"true\"><a rel=\"lightbox[130040]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/horizontal-featured.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-large wp-image-130254\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/horizontal-featured-700x262.jpg\" alt=\"Screenshots from a tablet with sample horizontal content\" width=\"700\" height=\"262\" \/><\/a><figcaption class=\"wp-caption-text\">Horizontal is rarely used but highly effective format for storytelling<\/figcaption><\/figure>\n<p>The Australian Broadcasting Corporation, the local public broadcaster, has always been an innovating force in the digital domain. The first organisation to\u00a0launch an online catch-up TV service in Australia, it often experiments and ultimately drives adoption of new technologies and approaches.<\/p>\n<figure id=\"attachment_130252\" class=\"wp-caption alignright\" data-caption=\"true\"><a rel=\"lightbox[130040]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/the_brief.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-130252 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/the_brief.jpg\" alt=\"Screenshot of the front page of a story from The Brief about beards\" width=\"480\" height=\"360\" \/><\/a><figcaption class=\"wp-caption-text\">The Brief shows how effective horizontal scroll can be<\/figcaption><\/figure>\n<p>When they launched two new digital magazines, the app-based <em>The Brief<\/em> and the Newstand-based <em>The White Paper<\/em> (interestingly built by the corporation&#8217;s radio arm), both repurposed existing content and melded the written word with audio, video, photographs and illustrations to deliver those stories to new audiences.<\/p>\n<p><em>Editor&#8217;s note: we have removed links as the above publications are no longer available.<\/em><\/p>\n<p>The Brief really caught my eye, and is the reason for this post, as it has taken the horizontal scrolling approach to delivering content.<\/p>\n<p>Horizontal scrolling is certainly not unique but it is rare, especially in the WordPress world. With the odd exception,\u00a0most\u00a0implementations are simply horizontal copies of vertical themes with a heavy emphasis on parallax effects that often results in a real gimmicky feel.<\/p>\n<p>The Brief, though, shows that horizontal doesn&#8217;t have to be gimmicky and although it requires more work than its vertical counterparts, the end result can be just as, if not more, effective especially for mobile devices.<\/p>\n<p>So, in this article we are going to walk through how we might implement horizontally scrolling posts and hopefully inspire you to explore this underutilized approach further.<\/p>\n<h2 id=\"make-content-horizontal\">Making Content Horizontal<\/h2>\n<p>In this implementation of horizontal scrolling we are not going to simply float all the content left and replace the vertical scroll bar with a horizontal scroll bar. That&#8217;s not going to provide much of an experience.<\/p>\n<p>Rather the content will be split into <em>sections<\/em>, pages if you will, which will be displayed one at a time, with simple previous and next navigation to navigate the sections.<\/p>\n<p>This gives a far more satisfying experience and also means that each section can be styled quite separately. It doesn&#8217;t take long when reading The Brief to see that the horizontal approach really does benefit from a variety of formatting.<\/p>\n<p>So, in our post we&#8217;ll use a simple <em>[section]<\/em> shortcode to wrap each section&#8217;s content. We&#8217;ll also use a <em>[block]<\/em> shortcode to enable manipulation of the section&#8217;s content. You&#8217;ll see how this works a little later.<\/p>\n<p>The shortcodes are set up in a plugin, which also sets up a filter that will override the template to be used to display a post if it has a custom field with a key of horizontal.<\/p>\n<p>I&#8217;ve included the template in the plugin folder and it is completely standalone just for ease of use but you may want to integrate it more closely with your site or even use a custom post type and simply take advantage of the WordPress template hierarchy.<\/p>\n<p>And finally, styling. Rather than create a hatful of shortcodes, I&#8217;ve kept it at just two and then used CSS to enhance the article with specific styles which are stored in a custom field, <em>post_style<\/em> and then output in the template. It&#8217;s a quick and dirty approach but it does allow\u00a0flexibility when playing with the solution.<\/p>\n<h2 id=\"get-horizontal\">Getting Horizontal With display:table-cell<\/h2>\n<p>As is nearly always the way, it&#8217;s rare that you have to start a project like this completely from scratch and a search for horizontal scrolling lead me to\u00a0<a href=\"http:\/\/www.webdesignerdepot.com\/author\/Ezequiel-Bruni\" target=\"_blank\">Ezequiel Bruni<\/a>&#8216;s <a title=\"Read the original article\" href=\"http:\/\/www.webdesignerdepot.com\/2014\/02\/how-to-create-horizontal-scrolling-using-display-table-cell\/\" rel=\"noopener\" target=\"_blank\">article on horizontal scrolling<\/a>\u00a0and this solution is based heavily on that article.<\/p>\n<p>The mark-up mimics a table: a containing <em>div<\/em> is set to <em>display:table<\/em> and <em>table-layout:fixed<\/em>; its child <em>section<\/em> elements are set to <em>display:table-cell<\/em>.<\/p>\n<p>There&#8217;s no need to float the sections, this happens automatically and so long as the <em>overflow<\/em> is <em>hidden<\/em> on the main container <em>div<\/em>, it&#8217;s simply a matter of scrolling the sections in and out of view to achieve the navigation between sections. The <a title=\"Learn more about this plugin\" href=\"http:\/\/plugins.jquery.com\/smooth-scroll\/\" rel=\"noopener\" target=\"_blank\">SmoothScroll jQuery plugin<\/a> is used for the scrolling.<\/p>\n<p>There&#8217;s also javascript to handle resizing the content to the window size, handling the navigation buttons and adding the ids to the sections.<\/p>\n<h2 id=\"test-content\">Walking Through The Test Content<\/h2>\n<p>I created 5 pages for the testing the plugin and playing with horizontal delivery. I&#8217;m going to walk through each one to explain what&#8217;s behind them.<\/p>\n<p>A few things to remember:<\/p>\n<ul>\n<li>add the style to a <em>post_style<\/em> custom field on the post<\/li>\n<li>add a <em>horizontal<\/em> custom field with the value of true<\/li>\n<li>sections are numbered and assigned <em>id<\/em>s automatically on the client-side, so make sure you know which section you are styling<\/li>\n<li>swap my test image links for your test image links!<\/li>\n<\/ul>\n<h3 id=\"simple-text-page\">The Simple Text Page<\/h3>\n<figure id=\"attachment_130250\" class=\"wp-caption aligncenter\" data-caption=\"true\"><a rel=\"lightbox[130040]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/Screen-Shot-2014-06-25-at-5.09.43-PM.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-large wp-image-130250\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/Screen-Shot-2014-06-25-at-5.09.43-PM-700x542.png\" alt=\"Screenshot of a two columns of text on a tablet\" width=\"700\" height=\"542\" \/><\/a><figcaption class=\"wp-caption-text\">Two columns of plain text<\/figcaption><\/figure>\n<p>Two columns of text, with no frills at all. Note, the columns are not automatically generated but are created by using two block shortcodes and setting the widths for each.<\/p>\n<h4>Content<\/h4>\n<pre>[section]\r\n&lt;h2&gt;Section 1&lt;\/h2&gt;\r\n[block]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ut tincidunt lorem, quis vestibulum lorem. Fusce volutpat eleifend eros id pharetra. Quisque eu nulla ligula. Mauris elementum urna eu consequat porta. Proin lacinia odio sed adipiscing semper. Ut sem mi, egestas vel placerat at, pulvinar quis tortor. Fusce sagittis massa vel dui rhoncus adipiscing.[\/block]<\/pre>\n<pre>[block]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ut tincidunt lorem, quis vestibulum lorem. Fusce volutpat eleifend eros id pharetra. Quisque eu nulla ligula. Mauris elementum urna eu consequat porta. Proin lacinia odio sed adipiscing semper. Ut sem mi, egestas vel placerat at, pulvinar quis tortor. Fusce sagittis massa vel dui rhoncus adipiscing.[\/block]\r\n[\/section]<\/pre>\n<h4>CSS Styles<\/h4>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n#section1 .block {\r\nwidth: 48%;\r\nmargin-right: 20px;\r\nfloat: left;\r\n}<\/pre>\n<h3 id=\"full-screen-image\">Full-screen Image With Text Overlay<\/h3>\n<figure id=\"attachment_199041\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-199041 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/section-2.png\" alt=\"Screenshot from a tablet with a full screen image of Captain America and sample text covering 30% of the page\" width=\"600\" height=\"465\" \/><figcaption class=\"wp-caption-text\">A far bigger visual punch with a full-screen image and a text overlay<\/figcaption><\/figure>\n<p>Full-screen images are easy to achieve by using the background-size: cover styling although depending on the size of the image you may have to play with the x and y settings to get the positioning you want. The text can either be set in a block or, as is the case here, the main content div itself can be styled.<\/p>\n<h4>Content<\/h4>\n<pre>[section]&lt;h2&gt;Section 2&lt;\/h2&gt;\r\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ut tincidunt lorem, quis vestibulum lorem. Fusce volutpat eleifend eros id pharetra. Quisque eu nulla ligula. Mauris elementum urna eu consequat porta. Proin lacinia odio sed adipiscing semper. Ut sem mi, egestas vel placerat at, pulvinar quis tortor. Fusce sagittis massa vel dui rhoncus adipiscing.[\/section]<\/pre>\n<h4>CSS Styles<\/h4>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n#section2 {\r\nbackground-color: #000000;\r\ncolor: #ffffff;\r\nbackground: url(http:\/\/www.test.dev\/wp-content\/uploads\/2013\/03\/captian-america.jpg) 50% 40%;\r\nbackground-size: cover;\r\n}\r\n\r\n#section2 .section-content {\r\nwidth: 30%;\r\ncolor: #ffffff;\r\nfont-weight: bold;\r\n}<\/pre>\n<h3 id=\"half-page-image-left\">Half-Page Image Left<\/h3>\n<div class=\"image-grid cgrid-row\">\n<div class=\"cgrid-col cgrid-col-span-full\">\n<figure id=\"attachment_199042\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-199042 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/section-3.png\" alt=\"Screenshot with image of Spider-Man talking up the full left-hand half of the page\" width=\"600\" height=\"465\" \/><figcaption class=\"wp-caption-text\">Background images are used to give the full half-page look to this page<\/figcaption><\/figure>\n<\/div>\n<\/div>\n<p>This technique also uses background images but this time the size is set to 50% so that it takes up half the page. The content then uses a left margin of 50% to ensure that it sits in the whitespace.<\/p>\n<h4>Content<\/h4>\n<pre>[section]&lt;h2&gt;Section 3&lt;\/h2&gt;\r\n Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ut tincidunt lorem, quis vestibulum lorem. Fusce volutpat eleifend eros id pharetra. Quisque eu nulla ligula. Mauris elementum urna eu consequat porta. Proin lacinia odio sed adipiscing semper. Ut sem mi, egestas vel placerat at, pulvinar quis tortor. Fusce sagittis massa vel dui rhoncus adipiscing.[\/section]<\/pre>\n<h4>CSS Styles<\/h4>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n#section3 {\r\nbackground-color: #000000;\r\nbackground: url(http:\/\/www.test.dev\/wp-content\/uploads\/2013\/03\/spider-man.jpg) top left no-repeat;\r\nbackground-size: 50%;\r\n}\r\n\r\n#section3 .section-content {\r\nwidth: 46%;\r\nmargin-left: 50%;\r\npadding: 20px;\r\n}<\/pre>\n<h3 id=\"half-page-image-tight\">Half-Page Image Right<\/h3>\n<figure id=\"attachment_130247\" class=\"wp-caption aligncenter\" data-caption=\"true\"><a rel=\"lightbox[130040]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/Screen-Shot-2014-06-25-at-5.10.08-PM.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-large wp-image-130247\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/Screen-Shot-2014-06-25-at-5.10.08-PM-700x542.png\" alt=\"Screengrab of a page with an image of Iron Man taking up the right-hand half of the page\" width=\"700\" height=\"542\" \/><\/a><figcaption class=\"wp-caption-text\">Same technique as the half-page left but image is fixed right<\/figcaption><\/figure>\n<p>The opposite of the half-page image left, the background image size is still set to 50% but this time it&#8217;s positioned on the right, rather than the left. No need to set a margin for the content, just a width.<\/p>\n<h4>Content<\/h4>\n<pre>[section]&lt;h2&gt;Section 4&lt;\/h2&gt;\r\n Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ut tincidunt lorem, quis vestibulum lorem. Fusce volutpat eleifend eros id pharetra. Quisque eu nulla ligula. Mauris elementum urna eu consequat porta. Proin lacinia odio sed adipiscing semper. Ut sem mi, egestas vel placerat at, pulvinar quis tortor. Fusce sagittis massa vel dui rhoncus adipiscing.[\/section]<\/pre>\n<h4>CSS Styles<\/h4>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n#section4 {\r\nbackground-color: #000000;\r\nbackground: url(http:\/\/www.test.dev\/wp-content\/uploads\/2013\/03\/ironman-2.jpg) top right no-repeat;\r\nbackground-size: 50%;\r\n}\r\n\r\n#section4 .section-content {\r\nwidth: 46%;\r\npadding: 20px;\r\n}<\/pre>\n<h3 id=\"full-page-image\">Full-Page Image, Opaque Text Overlay<\/h3>\n<figure id=\"attachment_199043\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-199043 size-full\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/section-5.png\" alt=\"Screengrab showing full-screen background image with a 75% opaque text box floating left\" width=\"600\" height=\"465\" \/><figcaption class=\"wp-caption-text\">Using an opaque background for the text makes it stand out more than just plain text<\/figcaption><\/figure>\n<h4>Content<\/h4>\n<pre>[section]&lt;h2&gt;Section 5&lt;\/h2&gt;\r\n Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ut tincidunt lorem, quis vestibulum lorem. Fusce volutpat eleifend eros id pharetra. Quisque eu nulla ligula. Mauris elementum urna eu consequat porta. Proin lacinia odio sed adipiscing semper. Ut sem mi, egestas vel placerat at, pulvinar quis tortor. Fusce sagittis massa vel dui rhoncus adipiscing.[\/section]<\/pre>\n<h4>CSS Styles<\/h4>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n#section5 {\r\nbackground-color: #000000;\r\nbackground: url(http:\/\/www.test.dev\/wp-content\/uploads\/2013\/03\/man-of-steel.jpg) 50% 50%;\r\nbackground-size: cover;\r\n}\r\n\r\n#section5 .section-content {\r\nbackground-color: #ffffff;\r\nopacity: 0.70;\r\nwidth: 40%;\r\nmargin-left: 20px;\r\npadding: 20px;\r\n}<\/pre>\n<p><strong>Remember!<\/strong>\u00a0When you are setting up your content, add following custom fields:<\/p>\n<ul>\n<li><em>horizontal<\/em> (value: true)<\/li>\n<li><em>post_style<\/em> (value: CSS styling for the post)<\/li>\n<\/ul>\n<h2 id=\"add-horizontal-mix\">Adding Horizontal To Your Mix<\/h2>\n<p>Horizontal certainly appears to have plenty of promise, especially on tablets. Content with plenty of images seems to work well, as does content where there&#8217;s plenty of potential variety in the sections.<\/p>\n<p>As well as playing with this plugin and content, if you turn these ideas and snippets into something more production-worthy then let everyone know in the comments below.<\/p>\n<p><em><strong>Editor\u2019s Note:<\/strong><\/em><em> This post has been updated for accuracy and relevancy. [Originally Published: Jun 2014 \/ Revised: April 2022]<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Horizontal scrolling is pretty much shunned by WordPress theme developers but is being embraced as a story telling technique particularly on tablets. So, look at how to bring horizontal scrolling content to your WordPress content.<\/p>\n","protected":false},"author":262394,"featured_media":207898,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[9900],"tutorials_categories":[],"class_list":["post-130040","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-content"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/130040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/262394"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=130040"}],"version-history":[{"count":12,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/130040\/revisions"}],"predecessor-version":[{"id":168897,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/130040\/revisions\/168897"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/207898"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=130040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=130040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=130040"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=130040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}