承接 pammel/simple-wordpress-cms 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pammel/simple-wordpress-cms

Composer 安装命令:

composer require pammel/simple-wordpress-cms

包简介

Use wordpress as CMS and embed generated pages in existing PHP project, e.g. laravel or symfony

README 文档

README

alt sketch

Use case

You have an existing PHP project and want to use Wordpress as CMS for specific pages. You only need the page content of the wordpress site, because header, footer, navigation etc. already exists on your site.

This is the concept of Simple-Wordpress-CMS:

  • It takes content and design from the wordpress page and embeds it into your PHP site.
  • The design of your existing site remains unaffected (e.g. header and footer). This is achieved by encapsulating CSS with Shadow DOM.
  • Links and URLs are fixed automatically. (SEO) meta tags also. Except image URLs, these remain the same, because images are stored on the Wordpress server.
  • It does not matter where Wordpress is installed, it can be any external server with different URL.

Installation

$ composer require pammel/simple-wordpress-cms

Quick start

Use this code to embed the Wordpress page into your PHP project:

<?php

use pammel\SimpleWordpressCms\Config;
use pammel\SimpleWordpressCms\Client;

$config = (new Config())
    ->setWordpressUrl('https://my-wordpress.com')
    ->setProjectUrl('https://my-php-project.com/wp')
    ->setCssFolderLocal('/var/www/my-php-project/public/css')
    ->setCssFolderPublicUrl('/css')
;

$page = (new Client($config))->getPage('my-first-page');  
?>

<html>
  <head>
    <!-- 
      Your existing html-head, which probably already has some head-tags in it. For example:
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    -->
    
    <? echo $page->getHtmlHead() ?>
  </head>
 
  <body>
    <header>
      <!-- Your existing header and navigation -->
    </header>
  
    <?php echo $page->getHtmlBody() ?>

    <footer>
      <!-- Your existing footer -->
    </footer>
  </body>
</html>

Features

For more functionality see

Caching

It is highly recommended to cache the page object because parsing the WordPress page takes a few seconds. This is an example using Laravel:

<?php

use Illuminate\Support\Facades\Cache;
use pammel\SimpleWordpressCms\Client;
use pammel\SimpleWordpressCms\Config;

$slug = 'my-first-page';

$cacheKey = md5('wordpress:' . $slug);
$page = Cache::remember($cacheKey, 3600, function() use($slug){
    $config = (new Config())
        ->setWordpressUrl('https://my-wordpress.com')
        ->setProjectUrl('https://my-php-project.com/wp')
        ->setCssFolderLocal('/var/www/my-php-project/public/css')
        ->setCssFolderPublicUrl('/css')
    ;

    return (new Client($config))->getPage($slug)->preprocess();
});

Troubleshooting

  • Don't use Wordpress themes that rely on JavaScript, especially for rendering.
  • I recommend lightweight themes such as https://generatepress.com. It does not use Javascript and it does not cause problems with shortcodes.
  • If there are not decoded "shortcodes" in your page, e.g. [vc_column_text]Hello World[/vc_column_text] you have to edit the function.php file of your wordpress theme and add something like this at the end of the file:
# wp-content\themes\<your-theme>\function.php
 
 ...
 
/**
 * Modify REST API content for pages to force
 * shortcodes to render since Visual Composer does not
 * do this
 */
add_action( 'rest_api_init', function ()
{
    register_rest_field(
       'page',
       'content',
       array(
          'get_callback'    => 'compasshb_do_shortcodes',
          'update_callback' => null,
          'schema'          => null,
       )
    );
});

function compasshb_do_shortcodes( $object, $field_name, $request )
{
    WPBMap::addAllMappedShortcodes(); // This does all the work

    global $post;
    $post = get_post ($object['id']);
    $output['rendered'] = apply_filters( 'the_content', $post->post_content );

    // EDIT: add custom CSS to $output:
    $output[ 'yb_wpb_post_custom_css' ] = get_post_meta( $object[ 'id' ], '_wpb_post_custom_css', true);

    return $output;
}

pammel/simple-wordpress-cms 适用场景与选型建议

pammel/simple-wordpress-cms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 03 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 pammel/simple-wordpress-cms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pammel/simple-wordpress-cms 我们能提供哪些服务?
定制开发 / 二次开发

基于 pammel/simple-wordpress-cms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-02