Git Product home page Git Product logo

mobilenews's Introduction

Mobile News

A React Native client to consume the WP Rest API. Currently only iOS. Android version will be added when iOS working prototype is complete.

##Setup Local setup is the same as the standard setup for react native.

##Modifications to the WordPress install

Currently, the client requires an addition of a featured_image_url field to the API response coming from WordPress to avoid having to make an additional API call for each featured image. This can be configured as follows (this code goes in functions.php or wherever actions are registered in your theme) :

add_action( 'rest_api_init', 'response_register_feat_img' );
function response_register_feat_img() {
    register_rest_field( 'post',
        'featured_image_url',
        array(
            'get_callback'    => 'response_get_feat_img',
            'update_callback' => null,
            'schema'          => null,
        )
    );
}

/**
 * Get the URL for the featured image for a given post
 *
 * @param array $object Details of current post.
 * @param WP_REST_Request $request Current request
 *
 * @return mixed
 */
function response_get_feat_img( $object, $request ) {
     return wp_get_attachment_url( get_post_thumbnail_id( $object[ 'id' ] ) );
}

In addition, the excerpt can be cleaned up a bit so that it doesn't render a screen reader link on a mobile device.

/**
 * Strip the screen reader content out of the excerpt
 *
 * @param string $output Original excerpt.
 *
 * @return string $output New excerpt
 */
function twentyten_custom_excerpt_more( $output ) {
	$pattern = '/(<span class=\"screen-reader-text\">.*)<\/p>/';
	$replacement = '';

	return preg_replace($pattern, $replacement, $output);
}
add_filter( 'the_excerpt', 'twentyten_custom_excerpt_more' );

mobilenews's People

Contributors

kkoppenhaver avatar

Watchers

 avatar  avatar

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.