]> _ Git - ccv-wordpress.git/commitdiff
WIP #3053
authorStephen Cameron <stephen@cubedesigners.com>
Thu, 12 Dec 2019 19:36:08 +0000 (20:36 +0100)
committerStephen Cameron <stephen@cubedesigners.com>
Thu, 12 Dec 2019 19:36:08 +0000 (20:36 +0100)
wp-content/mu-plugins/cube/src/Common/Setup.php
wp-content/themes/CCV/app/setup.php
wp-content/themes/CCV/resources/assets/styles/components/news.styl
wp-content/themes/CCV/resources/views/index.blade.php
wp-content/themes/CCV/resources/views/partials/content-single.blade.php
wp-content/themes/CCV/resources/views/partials/content.blade.php

index 5f5ff090cf76780e04fdb32899e6d5a19718423f..155790de84ae139792bc3187e01290fe33104680 100644 (file)
@@ -2,8 +2,6 @@
 
 namespace Cube\Common;
 
-use Carbon_Fields\Carbon_Fields;
-
 class Setup {
 
     /**
index 0d590eb5c7eb75eb32b148eeb76e3267aea60941..7b35087d9648c2500172b15411d2b3fea01cd5ef 100755 (executable)
@@ -6,6 +6,52 @@ use function Roots\asset;
 use function Roots\config;
 use function Roots\view;
 
+/**
+ * Override Elementor CSS order
+ * Normally, the Sage CSS is the last to load but we need Elementor's post specific CSS
+ * to load after the theme so it can override things like the padding. Elementor's default
+ * frontend CSS contains 10px padding on all populated elements, which messes with our
+ * designs so we override this in our theme. However, to override it, we are forced to use a
+ * CSS selector with high specificity in our theme's CSS:
+ * .elementor-column-gap-default > .elementor-row > .elementor-column > .elementor-element-populated
+ * When Elementor generates its post-xx.css files for custom styling set on a page, the specificity
+ * of this CSS rule is the same as ours so it can never override ours unless it is the last stylesheet
+ * to load. The desired loading order is:
+ * 1) Elementor Global / Frontend CSS
+ * 2) Sage Main CSS (Theme CSS)
+ * 3) Elementor post specific CSS (post-xx.css)
+ *
+ * Elementor has a hook when registering CSS files - https://code.elementor.com/hooks/elementor-css-file-name-enqueue/
+ * However, I couldn't get this to work properly with add_action and we need to use the post ID (get_the_ID()), which
+ * doesn't always seem to be available. I need to figure out where this hook should be added so that it is ready...
+ *
+ * For now, the solution is quite low-level and we inject a dependency of our theme's 'sage/main.css' CSS file into
+ * Elementor's post specific CSS file just before the stylesheets are printed. By having our theme as a dependency,
+ * Elementor's post-xx.css file is forced to load after the theme's CSS...
+ *
+ * TODO: revisit this and see if there's a better solution. See issue here: https://github.com/elementor/elementor/issues/7658
+ */
+add_action('wp_print_styles', function() {
+    global $wp_styles;
+    $sage_css_handle = 'sage/app.css';
+    $elementor_css_handle = 'elementor-post-'. get_the_ID();
+
+    // First, check if Elementor styles are loaded yet and if not, load them because we need to be able
+    // to make them a dependency of the main theme styles in order to have the correct CSS order...
+    // If we don't do this, on some pages that load Elementor late (eg. index.blade.php), the Elementor CSS
+    // will be loaded when fetching the builder content but it will be in the footer due to the late call.
+    // Although not perfect, it's easiest to always load the Elementor frontend CSS even if it's not strictly needed.
+    if (!isset($wp_styles->registered['elementor-frontend'])) {
+        \Elementor\Plugin::instance()->frontend->enqueue_styles();
+    }
+
+    if (isset($wp_styles->registered[$elementor_css_handle])) {
+        $wp_styles->registered[$elementor_css_handle]->deps = [$sage_css_handle];
+    }
+
+});
+
+
 /**
  * Theme assets
  */
@@ -23,7 +69,7 @@ add_action('wp_enqueue_scripts', function () {
 
     foreach ($styles as $stylesheet) {
         if (asset($stylesheet)->exists()) {
-            wp_enqueue_style('sage/' . basename($stylesheet, '.css'), asset($stylesheet)->uri(), false, null);
+            wp_enqueue_style('sage/' . basename($stylesheet, '.css'), asset($stylesheet)->uri(), ['elementor-frontend'], null);
         }
     }
 }, 100);
index f1b9654d87943f9356ca4c1d9649cd214ec1a77e..7cad486e5499b9b9f7774cfe6db0296880083f2d 100644 (file)
@@ -7,6 +7,7 @@
     constrain(margin-right, 5vw)
     constrain(margin-bottom, 5vw)
     max-width: 336px
+    min-width: 150px
 
     &-sizer
       padding-bottom: 100%
index e87293b28a107e229394117e1371bff19e341dc3..9e865ea46bfc76ee8ac0f961a268720f05c8c376 100644 (file)
@@ -2,11 +2,23 @@
 
 @section('content')
 
+  @php
+    // Insert the content from 'news-index-header' Elementor page
+    $page = get_page_by_path('news-index-header');
+    $translatedID = $page ? pll_get_post($page->ID) : null;
+
+    if ($translatedID) {
+      echo \Elementor\Plugin::instance()->frontend->get_builder_content_for_display($translatedID);
+    }
+
+  @endphp
+
+
   <div class="bg-light py-2v px-4v">
 
     <h1 class="h2">{!! get_the_title(get_option('page_for_posts', true)) !!}</h1>
 
-    <div class="mt-1v">
+    <div class="mt-2v">
 
       @if (! have_posts())
         @alert(['type' => 'warning'])
index e2ffd23e2c1aef2980d7a5cbfaa5e8e0af71af4b..f22c4b9c1581f1b2a57a5435c7b23dac7be589bb 100644 (file)
@@ -1,5 +1,5 @@
 <article @php(post_class('container px-2v pb-2v flex items-start sm:flex-wrap'))>
-  <header class="post-featured-image flex-shrink-0" style="background-image: url({{ get_the_post_thumbnail_url() }})">
+  <header class="post-featured-image" style="background-image: url({{ get_the_post_thumbnail_url() }})">
     <div class="post-featured-image-sizer">{{-- Just here as a proportional sizer thanks to the padding --}}</div>
   </header>
 
index ce62e9fcca9649b72b03e33965245e7117613845..35e2b2cd3643b3652e97f00d683a0b34a84f250f 100644 (file)
@@ -1,7 +1,9 @@
-<article @php(post_class('flex items-start'))>
+<article @php(post_class('flex items-start mt-1v sm:block sm:mt-12'))>
 
   <div class="post-featured-image" style="background-image: url({{ get_the_post_thumbnail_url() }})">
-    <div class="post-featured-image-sizer">{{-- Just here as a proportional sizer thanks to the padding --}}</div>
+    <a href="{{ get_permalink() }}">
+      <div class="post-featured-image-sizer">{{-- Just here as a proportional sizer thanks to the padding --}}</div>
+    </a>
   </div>
 
   <header>