Giter Site home page Giter Site logo

corcel-wpml's Introduction

Corcel WPML

This package allows you to use Corcel WordPress plugin with The WordPress Multilingual Plugin that allow you to easily build multilingual sites and run them. It’s powerful enough for corporate sites, yet simple for blogs.

Travis branch GitHub issues

Installation

This package is still in development

To install Corcel WPML, just run the following command:

composer require peakhmr/wpml

Packagist GitHub release

Usage


Posts

Every time you see Post::method(), if you're using your own Post class (where you set the connection name), like App\Post you should use App\Post::method() and not Post::method(). All the examples are assuming you already know this difference.

// All published posts
$posts = Post::published()->get();
$posts = Post::status('publish')->get();

// A specific post
$post = Post::find(31);
echo $post->post_title;

// Filter by meta/custom field
$posts = Post::published()->hasMeta('field')->get();
$posts = Post::hasMeta('acf')->get();

Pages

Pages are like custom post types. You can use Post::type('page') or the Page class.

// Find a page by slug
$page = Page::slug('about')->first(); // OR
$page = Post::type('page')->slug('about')->first();
echo $page->post_title;

For documentation please visit jgrossi/corcel for Corcel's usage and then come back here for how to use wpml plugin.

Translations

By using the $post object, we can access to the translation created by WPML.

Instead of using Corcel\Post, we use Wpml\Post to Override few variables. The plugin will look for wp_posts.ID in icl_translations.element_id and return a collection of icl_translations.trid.

// Find a translation collection by post id or slug
$post = Post::find(31)->translation(); \\ OR
$post = Post::slug('about')->translation();

\\ Result
TranslationCollection {#1855 ▼
  #changedKeys: []
  #items: array:2 [▼
    0 => Translation {
      #original: array:6 [▼
        "translation_id" => 38
        "element_type" => "post_page"
        "element_id" => 31
        "trid" => 19
        "language_code" => "en"
        "source_language_code" => null
      ]
    }
    1 => Translation {#1853 ▶}
  ]
}

Translate Post or Page

If you want to get the translated post object, use translate() scope and passing the icl_translations.language_code as parameter. This will return Corcel\Post object as expected.

// Find a translation collection by post id or slug

$lang = 'en'; \\ OR
$lang = config('app.locale');

$post = Post::slug('about')->translate($lang);

\\ Result
Page {#1847 ▼
  #postType: "page"
  #original: array:23 [▼
    "ID" => 6
    "post_author" => 1
    "post_date" => "2017-06-12 04:49:06"
    "post_date_gmt" => "2017-06-12 04:49:06"
    "post_content" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod."
    "post_title" => "Lorem ipsum dolor sit amet"
    ...
  ]
}

Advanced Custom Field, Field Keys

Add the follwing PHP script to your WordPress theme's function.php. This script will append a button Transfer Advanced Custom Field Accessor Keys to the Multilingual Content Seup section. This action button will toggle all _field_key as copy for you.

Multilingual Content Seup

  function acf_admin_script()
  { ?>

    <!-- Update Admin Script For Advanced Custom Field -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript">

      /**
      * Advanced Custom Field Accessor key copy tools
      */

      $(document).ready(function() {
        $('#icl_div_config #icl_mcs_details p').prepend('<a onclick="apply_acf_accessor()" class="preview button">Transfer Advanced Custom Field Accessor Keys</a>')
      });

      function apply_acf_accessor() {
        var table = $('#icl_div_config #icl_mcs_details table tbody');
        var expression = /^_[\d\S]+/;
        var rows = table[0].rows;

        for (var i = 0; i < rows.length; i++) {
          var element = $(rows[i]);
          var validator = $(rows[i]).find('td[id]')[0].textContent;

          if (expression.test(validator)) {
            $(element).css({
              background: 'rgba(207, 73, 68, 0.3)'
            }).find('td').css({
              color: '#333'
            });
            $(element).find('td[align] label:nth-child(2) input').prop('checked', 'checked');
          }

        }
      }

    </script>

  <?php }
  add_action('admin_enqueue_scripts', 'acf_admin_script');

License

license

corcel-wpml's People

Contributors

jpmaga avatar socheatsok78 avatar

Watchers

 avatar  avatar

Forkers

mello21century

corcel-wpml's Issues

Error instaling...

Im running "jgrossi/corcel": "^2.4",

`Your requirements could not be resolved to an installable set of packages.

Problem 1
- peakhmr/wpml v1.0.6 requires jgrossi/corcel ^1.4 -> satisfiable by jgrossi/corcel[v1.4.0, v1.4.1, v1.4.2, v1.4.3, v1.4.4, v1.4.5, v1.4.6, v1.4.7] but these conflict with your requirements or minimum-stability.
- peakhmr/wpml v1.0.5 requires jgrossi/corcel ^1.4 -> satisfiable by jgrossi/corcel[v1.4.0, v1.4.1, v1.4.2, v1.4.3, v1.4.4, v1.4.5, v1.4.6, v1.4.7] but these conflict with your requirements or minimum-stability.
- peakhmr/wpml v1.0.4 requires jgrossi/corcel ^1.4 -> satisfiable by jgrossi/corcel[v1.4.0, v1.4.1, v1.4.2, v1.4.3, v1.4.4, v1.4.5, v1.4.6, v1.4.7] but these conflict with your requirements or minimum-stability.
- peakhmr/wpml v1.0.3 requires jgrossi/corcel ^1.4 -> satisfiable by jgrossi/corcel[v1.4.0, v1.4.1, v1.4.2, v1.4.3, v1.4.4, v1.4.5, v1.4.6, v1.4.7] but these conflict with your requirements or minimum-stability.
- peakhmr/wpml v1.0.2 requires jgrossi/corcel ^1.4 -> satisfiable by jgrossi/corcel[v1.4.0, v1.4.1, v1.4.2, v1.4.3, v1.4.4, v1.4.5, v1.4.6, v1.4.7] but these conflict with your requirements or minimum-stability.
- peakhmr/wpml v1.0.1 requires jgrossi/corcel ^1.4 -> satisfiable by jgrossi/corcel[v1.4.0, v1.4.1, v1.4.2, v1.4.3, v1.4.4, v1.4.5, v1.4.6, v1.4.7] but these conflict with your requirements or minimum-stability.
- peakhmr/wpml v1.0.0 requires jgrossi/corcel ^1.4 -> satisfiable by jgrossi/corcel[v1.4.0, v1.4.1, v1.4.2, v1.4.3, v1.4.4, v1.4.5, v1.4.6, v1.4.7] but these conflict with your requirements or minimum-stability.
- Installation request for peakhmr/wpml ^1.0 -> satisfiable by peakhmr/wpml[v1.0.0, v1.0.1, v1.0.2, v1.0.3, v1.0.4, v1.0.5, v1.0.6].

Installation failed, reverting ./composer.json to its original content.`

Is it usable? how?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.