Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch posts directive #8

Merged
merged 3 commits into from
Feb 7, 2019
Merged

Conversation

dawidurbanski
Copy link
Contributor

I made a new pull request to use patch specific branch so I can use my fork master branch as a separate package until this is merged.

All informations can be found in #6

@Log1x Log1x merged commit 722ae7b into Log1x:master Feb 7, 2019
@Log1x
Copy link
Owner

Log1x commented Feb 7, 2019

Sorry for the delay. Fixing a few things with a couple other fields and then I'll publish a release.

Good work!

Log1x added a commit that referenced this pull request Feb 12, 2019
Added 12+ new helper directives: `@istrue, @isFalse, @IsNull, @isnotnull, @instanceof, @typeof, @repeat, @Style, @script, @js, @inline, @fa`
Added 6 new WordPress directives: `@author, @authorurl, @published, @Modified, @wpautop, @wpautokp`
Refactored `@posts` allowing it to accept post IDs, `WP_Post` instances, or an array with a combination of the two (#8)
Refactored source code DocBlocks and formatting of directives
Improved formatting and examples for documentation
Fix missing closing parenthesis in fields directive (#7)
Added missing parameters to allow passing an array key to `@isfield`, `@issub`, and `@isoption`
@Log1x
Copy link
Owner

Log1x commented Feb 12, 2019

@dawidurbanski I've pushed v1.0.4. It includes a slightly refactored version of this as well as some other goodies. Let me know if you find any bugs.

@dawidurbanski
Copy link
Contributor Author

dawidurbanski commented Feb 12, 2019

@Log1x Wow! Huge update! Thank you very much!

One issue i can see is backward compatibility with @condition, I think you should leave it there for some time and mark it as deprecated, or remove from docs, but keep in code. I can see one updating version of this library for new features, in the same time breaking exisiting templates using this directive :)

I'm actually implementing your library in my first project and I can see even some more improvements, but I'm gonna wrap it up in the end of the project at once.

For example ACF gallery field is unsupported as it uses foreach loop instead of have_fields. So I made couple directives to address this issue:

dawidurbanski@e670265

Additionaly it would be cool to use just @permalink instead of {{ get_permalink }}, @postclass instead @php post_class() @endphp,

Also wp_get_attachment_image wrapper would be nice addition. For example if we set ACF image field to return ID of attachment, then instead of:

{!! wp_get_attachment_image(get_sub_field('image'), 'thumbnail', true, ['class' => 'svg icon']) !!}

We do:

@image('image', 'thumbnail', ['class' => 'svg icon'])

or

@icon('image', 'thumbnail', ['class' => 'svg icon']) // sets third parameter (icon) to true

I'm using wp_get_attachment_image beacuse it returns nice responsive image with srcset and sizes.

Including widgetizet areas (sidebars):

@php dynamic_sidebar('sidebar-footer-1') @endphp => @sidebar('sidebar-footer-1')

And also consider some of the following (to further cleanup base layouts and other partials):

@php wp_head() @endphp => @wphead
{!! get_language_attributes() !!} => @languageatts
@php body_class() @endphp => @bodyclass
@php do_action('get_header') @endphp => @getheader
@php do_action('get_footer') @endphp => @getfooter
@php wp_footer() @endphp => @wpfooter

After I'm done with current project, I'm gonna try to make some pull requests if welcome :)

Great job once again!
👍 👍 👍

@Log1x
Copy link
Owner

Log1x commented Feb 12, 2019

No problem!

I'd appreciate the PR's. I had also thought of post thumbnails, author avatars, sidebars, and a couple other things but I'm a little backed up with work right now from having spent the past day or two on this so I wanted to at least get it rolled out. Most are pretty easy implementations, though. I think it might be about time to move the documentation to its own USAGE.md or something though. 🙈

I can add @condition back– I mainly just threw it out because I felt like it was unlikely that many people were using it in its state.

@dawidurbanski
Copy link
Contributor Author

In my case, I used it to apply some classes if the page is using content created by Gutenberg, or classic editor (if not I don't want any spacing inside content as it's populated from ACF flexible content and each block is responsible for adding such).

<div class="container
            @condition(has_blocks(), 'gutenberg-content')
            @condition('' !== get_post()->post_content, 'has-content')">
  @include('partials.page-header')
  @include('partials.content-page')
</div>

@intelligence
Copy link

@dawidurbanski How are you using the @images directive? I can't get it to work after adding your code to ACF.php and then trying this in my template:

@images('gallery')
  <div>
    @image()
  </div>
@endimages

@dawidurbanski
Copy link
Contributor Author

@intelligence I don't see any @images directive being available in Sage directives.

You need to create your own loop and use @image() inside.

@hasfield('gallery')
  <div class="gallery">
    @foreach (get_field('gallery') as $image)
      <div class="image">
        @image($image)
      </div>
    @endforeach
  </div>
@endfield

@intelligence
Copy link

Ah, yeah. That makes sense, thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants