PHP code example of kayue / kayue-wordpress-bundle

1. Go to this page and download the library: Download kayue/kayue-wordpress-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kayue / kayue-wordpress-bundle example snippets



// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Kayue\WordpressBundle\KayueWordpressBundle(),
    );
    // ...
}


// path/to/controller.php

public function postAction($slug)
{
    $repo = $this->get('kayue_wordpress')->getManager()->getRepository('KayueWordpressBundle:Post');
    $post = $repo->findOneBy(array(
        'slug'   => 'hello-world',
        'type'   => 'post',
        'status' => 'publish',
    ));

    echo $post->getTitle() , "\n";
    echo $post->getUser()->getDisplayName() , "\n";
    echo $post->getContent() , "\n";

    foreach($post->getComments() as $comment) {
        echo $comment->getContent() . "\n";
    }

    foreach($post->getTaxonomies()->filter(function(Taxonomy $tax) {
        // Only return categories, not tags or anything else.
        return 'category' === $tax->getName();
    }) as $tax) {
        echo $tax->getTerm()->getName() . "\n";
    }

    // ...
}



public function firstPostAction()
{
    // Method 1: Switch current blog's id. Similar to WordPress's `switch_to_blog()` method.
    // Changing the current blog ID will affect Twig extensions too.
    $blogManager = $this->get('kayue_wordpress')->getManager();
    $blogManager->setCurrentBlogId(2);
    $this->getRepository('KayueWordpressBundle:Post')->findOnePostById(1);

    // Method 2: Use entity manager if you don't want to switch the entire blog.
    // This won't change the current blog ID.
    $blogId = 3;
    $anotherBlog = $this->get('kayue_wordpress')->getManager($blogId);
    $posts = $anotherBlog->getRepository('KayueWordpressBundle:Post')->findOneById(1);
}



use Kayue\WordpressBundle\Wordpress\Shortcode\ShortcodeInterface;

class GalleryShortcode implements ShortcodeInterface
{
    public function getName()
    {
        return 'gallery';
    }

    public function($attr, $content = null)
    {
        // do your things...

        return "<p>Return HTML</p>";
    }
}
}