Skip to content

Instantly share code, notes, and snippets.

@rashanoureldin
Created June 30, 2012 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rashanoureldin/3024748 to your computer and use it in GitHub Desktop.
Save rashanoureldin/3024748 to your computer and use it in GitHub Desktop.
portfolio-with-wordpress
<?php
/**
* Custom Child Theme Functions
*
* This file's parent directory can be moved to the wp-content/themes directory
* to allow this Child theme to be activated in the Appearance - Themes section of the WP-Admin.
*
* Included are a set of constants that can be defined to customize aspects of Thematic's
* functionality, as well as a sample function that will add a home link to your menu.
* "Uncomment" or add more to cusomize the functionality of your Child Theme.
*
* More ideas can be found in the community documentation for Thematic
* @link http://docs.thematictheme.com
*
* @package ThematicSampleChildTheme
* @subpackage ThemeInit
*/
// Unleash the power of Thematic's dynamic classes
//
// define('THEMATIC_COMPATIBLE_BODY_CLASS', true);
// define('THEMATIC_COMPATIBLE_POST_CLASS', true);
// Unleash the power of Thematic's comment form
//
// define('THEMATIC_COMPATIBLE_COMMENT_FORM', true);
// Unleash the power of Thematic's feed link functions
//
// define('THEMATIC_COMPATIBLE_FEEDLINKS', true);
// Adds a home link to your menu
// http://codex.wordpress.org/Template_Tags/wp_page_menu
//function childtheme_menu_args($args) {
// $args = array(
// 'show_home' => 'Home',
// 'sort_column' => 'menu_order',
// 'menu_class' => 'menu',
// 'echo' => false
// );
// return $args;
//}
//add_filter('wp_page_menu_args','childtheme_menu_args');
?>
<?php
/* ********************************************** */
/* Remove the standard Thematic menu */
/* ********************************************** */
function remove_menu() {
remove_action('thematic_header','thematic_access',9);
}
add_action('init', 'remove_menu');
// Moving the thematic menu above the header
add_action('thematic_header','thematic_access',6);
/* ********************************************** */
/* Register Menu */
/* ********************************************** */
function register_my_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu' ),
'footer-menu' => __( 'Footer Menu' ),
'side-menu' => __( 'Side Menu' ),
)
);
}
add_action( 'init', 'register_my_menus' );
/* ********************************************** */
/* Footer Menu */
/* ********************************************** */
function footer_menu() {
if ( has_nav_menu( 'footer-menu' ) ) {
wp_nav_menu( array( 'theme_location' => 'footer-menu',
'container_class'=>'footer-menu',
'menu_class' => 'sf-menu', // we assign the sf-menu class to the menu ul so that superfish works on this menu too
) );
}
}
add_action('thematic_footer','footer_menu',41);
/* ********************************************** */
/* Footer Social Menu */
/* ********************************************** */
function social_menu(){ ?>
<div class="social">
<ul class="sf-menu">
<li><a href="#">Follow Us</a></li>
<li><a href="#"><img src="images/Facebook.png" width="16" height="16" /></a></li>
<li><a href="#"><img src="images/Twitter.png" width="16" height="16" /></a></li>
<li><a href="#"><img src="images/Skype.png" width="16" height="16" /></a></li>
</ul>
</div>
<?php }
add_action('thematic_footer','social_menu',44);
/* ********************************************** */
/* Portfolio */
/* ********************************************** */
add_action('init', 'project_custom_init');
/*-- Custom Post Init Begin --*/
function project_custom_init()
{
$labels = array(
'name' => _x('Projects', 'post type general name'),
'singular_name' => _x('Project', 'post type singular name'),
'add_new' => _x('Add New', 'project'),
'add_new_item' => __('Add New Project'),
'edit_item' => __('Edit Project'),
'new_item' => __('New Project'),
'view_item' => __('View Project'),
'search_items' => __('Search Projects'),
'not_found' => __('No projects found'),
'not_found_in_trash' => __('No projects found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'Project'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','author','thumbnail','excerpt','comments', 'post-formats')
);
// The following is the main step where we register the post.
register_post_type('project',$args);
// Initialize New Taxonomy Labels
$labels = array(
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Types' ),
'all_items' => __( 'All Tags' ),
'parent_item' => __( 'Parent Tag' ),
'parent_item_colon' => __( 'Parent Tag:' ),
'edit_item' => __( 'Edit Tags' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
);
// Custom taxonomy for Project Tags
register_taxonomy('tagportifolio',array('project'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'tag-portifolio' ),
));
}
/*-- Custom Post Init Ends --*/
/*--- Custom Messages - project_updated_messages ---*/
add_filter('post_updated_messages', 'project_updated_messages');
function project_updated_messages( $messages ) {
global $post, $post_ID;
$messages['project'] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __('Project updated. <a href="%s">View project</a>'), esc_url( get_permalink($post_ID) ) ),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __('Project updated.'),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision']) ? sprintf( __('Project restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Project published. <a href="%s">View project</a>'), esc_url( get_permalink($post_ID) ) ),
7 => __('Project saved.'),
8 => sprintf( __('Project submitted. <a target="_blank" href="%s">Preview project</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Project scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview project</a>'),
// translators: Publish box date format, see http://php.net/date
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Project draft updated. <a target="_blank" href="%s">Preview project</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
/*--- #end SECTION - project_updated_messages ---*/
/*--- Demo URL meta box ---*/
add_action('admin_init','portfolio_meta_init');
function portfolio_meta_init()
{
// add a meta box for wordpress 'project' type
add_meta_box('portfolio_meta', 'Project Infos', 'portfolio_meta_setup', 'project', 'side', 'low');
// add a callback function to save any data a user enters in
add_action('save_post','portfolio_meta_save');
}
function portfolio_meta_setup()
{
global $post;
?>
<div class="portfolio_meta_control">
<label>URL</label>
<p>
<input type="text" name="_url" value="<?php echo get_post_meta($post->ID,'_url',TRUE); ?>" style="width: 100%;" />
</p>
</div>
<?php
// create for validation
echo '<input type="hidden" name="meta_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
}
function portfolio_meta_save($post_id)
{
// check nonce
if (!isset($_POST['meta_noncename']) || !wp_verify_nonce($_POST['meta_noncename'], __FILE__)) {
return $post_id;
}
// check capabilities
if ('post' == $_POST['post_type']) {
if (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
} elseif (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
// exit on autosave
if (defined('DOING_AUTOSAVE') == DOING_AUTOSAVE) {
return $post_id;
}
if(isset($_POST['_url']))
{
update_post_meta($post_id, '_url', $_POST['_url']);
} else
{
delete_post_meta($post_id, '_url');
}
}
/*--- #end Demo URL meta box ---*/
function enqueue_filterable()
{
wp_register_script( 'filterable', get_template_directory_uri() . '/js/filterable.js', array( 'jquery' ) );
wp_enqueue_script( 'filterable' );
}
add_action('wp_enqueue_scripts', 'enqueue_filterable');
?>
<?php
if(!function_exists('getPageContent'))
{
function getPageContent($pageId,$max_char)
{
if(!is_numeric($pageId))
{
return;
}
global $wpdb;
$nsquery = 'SELECT DISTINCT * FROM ' . $wpdb->posts .
' WHERE ' . $wpdb->posts . '.ID=' . $pageId;
$post_data = $wpdb->get_results($nsquery);
if(!empty($post_data))
{
foreach($post_data as $post)
{
$text_out=nl2br($post->post_content);
$text_out=str_replace(']]>', ']]&gt;', $text_out);
$text_out = strip_tags($text_out);
return substr($text_out,0,$max_char);
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment