add_action('typerocket_loaded', function() {
$person = \tr_post_type('Person', 'People')
->setIcon('users')
- ->setArgument('publicly_queryable', false) // No public page, just used as part of other posts
+ ->setAdminOnly() // No public page, just used as part of other posts
->setArgument('supports', ['title']) // No editor for this post type
->setTitlePlaceholder('Enter full name here')
->setTitleForm(function() {
namespace Cube\CPT;
+use \App\Fields\PostTypeSelect;
+
class ScientificNews {
public function register() {
// Wait for TypeRocket to load before adding post type
add_action('typerocket_loaded', function() {
- $science_news = \tr_post_type('Scientific News')
+
+ // Custom Post Type for Scientific News
+ \tr_post_type('Scientific News')
->setIcon('flask')
- ->setEditorForm(function() {
+ ->addSupport('post_details'); // Adds meta box "Post Details" that we created below
+
+ // post_details metabox that we put in the right sidebar
+ \tr_meta_box('Post Details')
+ ->setContext('side')
+ ->setCallback(function() {
$form = \tr_form();
+
+ $person = new PostTypeSelect('Published By', $form);
+ echo $person->setPostType('person');
+
echo $form->gallery('Images');
- echo $form->search('Published By')->setPostType('person');
- });
+ });
+
+
});
}
--- /dev/null
+<?php
+
+namespace App\Fields;
+
+use TypeRocket\Elements\Fields\Select;
+
+class PostTypeSelect extends Select
+{
+ protected function init() {
+ $this->setType( 'post_type_select' );
+ }
+
+ public function getString() {
+
+ $posts = get_posts([
+ 'post_type' => $this->getSetting('post_type'),
+ 'numberposts' => -1, // Get all posts
+ 'orderby' => 'post_title',
+ 'order' => 'ASC',
+ ]);
+
+ $options = ['' => '(not set)'] + collect($posts)->pluck('post_title', 'ID')->all();
+
+ $this->setOptions($options, 'flip'); // Flipping the options because the select expects the label as the key
+
+ // Now that the options are set, we can use the normal output of the parent class
+ return parent::getString();
+ }
+
+ /**
+ * Set the post type to source dropdown options from
+ *
+ * @param string $type
+ *
+ * @return $this
+ */
+ public function setPostType($type)
+ {
+ $this->setSetting('post_type', $type);
+ return $this;
+ }
+
+}
--- /dev/null
+<?php
+
+namespace App\Composers;
+
+use Roots\Acorn\View\Composer;
+
+class ScientificNews extends Composer
+{
+ /**
+ * List of views served by this composer.
+ *
+ * @var array
+ */
+ protected static $views = [
+ 'partials.content-single-scientific_news',
+ ];
+
+ /**
+ * Data to be passed to view before rendering.
+ *
+ * @return array
+ */
+ public function with()
+ {
+ return [
+ 'published_by' => $this->published_by(),
+ 'images' => $this->images(),
+ ];
+ }
+
+ /**
+ * Returns the images the attributed publisher of the post, if any
+ *
+ * @return mixed
+ */
+ public function published_by()
+ {
+ $published_by = tr_posts_field('published_by');
+ if (!$published_by) return false;
+
+ $person = get_post($published_by);
+ if (!$person) return false;
+
+ // Get the photo ID if set
+ $photo = get_post_meta($person->ID, 'photo', true);
+
+ return [
+ 'name' => $person->post_title,
+ 'photo' => $photo,
+ ];
+ }
+
+ /**
+ * Returns the images attached to this post, if any
+ *
+ * @return mixed
+ */
+ public function images()
+ {
+ return tr_posts_field('images');
+ }
+}
@import 'common/global'
@import 'common/admin'
@import 'common/layout'
-@import 'common/spacing'
@import 'common/animations'
// MMenu base styles from NPM package
@import 'widgets/*'
//@import 'pages/*'
+// Allow spacing classes to override others defined here
+@import 'common/spacing'
+
/*! purgecss end ignore */
// Utilities go last in source order so they can
// Tiny MCE editor styles in Elementor editor
// Most styles for editor set in text-block.styl body...
#tinymce
- @apply font-body p-3
+ @apply font-body
+ @apply p-3 !important
// Normally the lists have no margin and the bullet > image sits
// in the spacing gutter created by the text-block. In the context
&-featured-image
@apply bg-cover bg-center
- @apply w-full
background-color: #ddd
constrain(margin-right, 5vw)
constrain(margin-bottom, 5vw)
max-width: 336px
min-width: 150px
+ flex-basis: 30%
&-sizer
padding-bottom: 100%
--- /dev/null
+@extends('layouts.app')
+
+@section('content')
+
+
+ <div class="bg-light py-2v px-4v">
+
+ <h1 class="h2">{{ __('Actualité Scientifique') }}</h1>
+
+ <div class="mt-2v">
+
+ @if (! have_posts())
+ @alert(['type' => 'warning'])
+ {{ __('Sorry, no results were found.', 'sage') }}
+ @endalert
+
+ {!! get_search_form(false) !!}
+ @endif
+
+ @while (have_posts()) @php(the_post())
+ @includeFirst(['partials.content-'.get_post_type(), 'partials.content'])
+ @endwhile
+
+ {!! get_the_posts_navigation() !!}
+
+ </div>
+
+ </div>
+@endsection
+
+@section('sidebar')
+ @include('partials.sidebar')
+@endsection
--- /dev/null
+<article @php(post_class('flex items-start mt-1v sm:block sm:mt-12'))>
+
+ <div class="post-featured-image min-w-0 mr-1v mb-1v" style="background-image: url({{ get_the_post_thumbnail_url() }}); max-width: 135px;">
+ <a href="{{ get_permalink() }}">
+ <div class="post-featured-image-sizer">{{-- Just here as a proportional sizer thanks to the padding --}}</div>
+ </a>
+ </div>
+
+ <header style="flex-basis: 100%">
+ <h2 class="plain text-lg mb-2">
+ <a href="{{ get_permalink() }}">
+ {!! $title !!}
+ </a>
+ </h2>
+
+ <div class="entry-summary">
+ @php(the_excerpt())
+ </div>
+
+ <p class="mt-6 mb-1v">
+ <a class="uppercase text-pink inline-flex items-center" href="{{ get_permalink() }}">
+ @svg('arrow', 'h-3 mr-2 fill-current')
+ <?= __('Lire la suite') ?>
+ </a>
+ </p>
+
+ </header>
+
+</article>
<header class="mr-2v mb-2v">
- <div class="pb-8">
- <em>{{ __('Publié par') }}</em>
- <br/>
- {{-- Todo: get linked post type data for user from published_by ID --}}
- <strong>{{ tr_posts_field('published_by') }}</strong>
- </div>
-
- @foreach(tr_posts_field('images') as $image)
- <div class="post-featured-image mb-4" style="background-image: url({{ wp_get_attachment_image_url($image, 'full') }})">
- <div class="post-featured-image-sizer">{{-- Just here as a proportional sizer thanks to the padding --}}</div>
+
+ @if ($published_by)
+ <div class="pb-8 text-center">
+ <div class="mx-auto rounded-full bg-light bg-cover bg-center mb-2"
+ style="background-image: url({{ wp_get_attachment_image_url($published_by['photo'], 'medium') }}); max-width: 135px">
+ <div class="pb-100%">{{-- Image sizer to make square --}}</div>
+ </div>
+ <em>{{ __('Publié par') }}</em>
+ <br/>
+ <strong>{{ $published_by['name'] }}</strong>
</div>
+ @endif
+
+ @foreach($images as $image)
+ {!! wp_get_attachment_image($image, 'medium', false, ['class' => 'mb-4']) !!}
@endforeach
</header>
- <div class="entry-content mb-2v">
- <h1 class="plain my-4 h2">
+ <div class="entry-content mb-2v" style="flex-basis: 70%">
+ <h1 class="plain mb-4 h2">
{!! $title !!}
</h1>
</a>
</div>
- <header>
+ <header style="flex-basis: 100%">
@include('partials/entry-meta')
<h2 class="plain my-4">