Skip to content

Instantly share code, notes, and snippets.

@cdsalmons
Forked from wycks/GhettoPress.php
Last active August 29, 2015 14:26
Show Gist options
  • Save cdsalmons/cf378292f6cc01e66087 to your computer and use it in GitHub Desktop.
Save cdsalmons/cf378292f6cc01e66087 to your computer and use it in GitHub Desktop.
WordPress Ghetto Loader - stop doing this, you
<?php
//Load WorsPress quick and dirty into something not WordPress. This is horrible I know,
//But the database queries they are so low, and it's just so dirty
//install WordPress in a dir like /lib or something and stick classPageLoader.php in there, ha!
//Example use for a index.php or whatever, no autoloading here!
#######################################################
require('lib/classPageLoader.php');
$content = new LoadWpContent();
## bunch of html
//pass ID
echo $content->getPostTitle( '9' );
echo $content->getPostContent( '9' );
echo $content->getPostImages( '9', 'thumbnail' );
## bunch of html - that's it!
########################################################
#/lib/classPageLoader.php
/*
* LoadWpContent class
* Loads WordPress Stuff
*
* I should refactor all this right
*/
class LoadWpContent {
/**
* Load WP
* require is hardcoded to a /lib dir for WordPress install - change at will
*/
public function __construct() {
define('WP_USE_THEMES', false);
require('lib/wp-load.php');
}
/**
* Grab WordPress pages by slug (name)
*
* @param string $page page slug
* @param string $content page content
* @return $content
*/
public function getPageContent( $pagename ){
$page = get_page_by_title( $pagename );
$content = apply_filters( 'the_content', $page->post_content );
return $content;
}
/**
* Grab WordPress page or post by ID
*
* @param string $post
* @param string $content page/post content
* @return $content
*/
public function getPostContent( $postid ){
$post = get_post( $postid );
$content = apply_filters( 'the_content', $post->post_content );
return $content;
}
/**
* Grab WordPress page or post title by ID
*
* @param string $post
* @param string $title page/post title
* @return $title
*/
public function getPostTitle( $postid ){
$post = get_post( $postid );
$title = $post->post_title;
return $title;
}
/**
* Grab WordPress images attached to a post by ID
*
* @param string $post
* @param string $images page/post images
* @return $images
*/
public function getPostImages( $postid , $size){
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'post_status' => 'inherit',
'post_parent' => $postid,
'orderby' => 'menu_order',
'order' => 'ASC',
);
//instead return the array
$attachments = get_children( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment_id => $attachment ) {
echo wp_get_attachment_image( $attachment_id, $size );
}
}
}
}
########### Create a dummy theme
// theme functions.php
function unregister_default_wp_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Text');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Recent_Posts');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_RSS');
unregister_widget('WP_Widget_Tag_Cloud');
unregister_widget('WP_Nav_Menu_Widget');
}
add_action('widgets_init', 'unregister_default_wp_widgets', 1);
// theme index.php
header("Location: http://example.com");
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment