Punto informatico Network
Login Esegui login | Non sei registrato? Iscriviti ora (è gratuito!)
Username: Password:
  • Annuncio Pubblicitario

modificare php..help!

Cerchi consigli per migliorare il tuo sito? Vuoi aprire un sito in poco tempo?
Discuti con altri webmaster, chiedi chiarimenti ed opinioni in tutta libertà.
Lo spam verrà cancellato.

modificare php..help!

Messaggioda Martina Stella » ven giu 18, 2010 6:06 pm

Salve a tutti ho trovato un plugin che permette di inserire gli articoli nelle diverse pagine del sito. Il problema è che riporta soltanto i titoli degli articoli. I vorrei che apparisse un riassunto, magari sfruttando anche il plugin Evermore che già ho. comunque questo plugin è Post Page Associator.

Credo davvero che basti poco però io non so come modificare il php e quindi lascio a voi....

<?php

/*

Plugin Name: Post Page Associator
Plugin URI: http://dennishoppe.de/wordpress-plugins ... associator
Description: The Post-Page-Associator enables you to attach posts to a page.
Version: 1.2.12
Author: Dennis Hoppe
Author URI: http://DennisHoppe.de

*/


// Please think about a donation
If (Is_File(DirName(__FILE__).'/donate.php')) Include DirName(__FILE__).'/donate.php';


If (!Class_Exists('wp_plugin_associate_posts_and_pages')){
Class wp_plugin_associate_posts_and_pages {
var $base_url;
var $text_domain;
var $current_post;

Function __construct(){
// Read base
$this->base_url = get_bloginfo('wpurl').'/'.Str_Replace("\\", '/', SubStr(RealPath(DirName(__FILE__)), Strlen(ABSPATH)));

// Get ready to translate
$this->Load_TextDomain();

// This Plugin supports post thumbnails
If (Function_Exists('Add_Theme_Support'))
Add_Theme_Support('post-thumbnails');

// Hooks
If (Is_Admin()){
Add_Action('admin_menu', Array($this, 'add_settings_page'));
Add_Action('admin_menu', Array($this, 'save_settings_page'));

Add_Action('admin_menu', Array($this, 'add_meta_box'));
Add_Action('save_post', Array($this, 'save_meta_box'));

Add_Action('admin_head', Array($this, 'add_admin_header'));
}
Else {
Add_Filter('the_content', Array($this, 'filter_content'), 9);
}

// Shortcodes
Add_Shortcode('associated_posts', Array($this, 'shortcode'));
}

Function Load_TextDomain(){
$this->text_domain = get_class($this);
load_textdomain ($this->text_domain, DirName(__FILE__).'/language/'.get_locale().'.mo');
}

Function t ($text, $context = ''){
// Translates the string $text with context $context
If ($context == '')
return __($text, $this->text_domain);
Else
return _x($text, $context, $this->text_domain);
}

Function get_setting_key(){ return __CLASS__; }

Function get_meta_key(){ return '_' . __CLASS__; }

Function add_settings_page (){
add_settings_field( get_class($this), $this->t('Associated posts'), Array($this, 'print_settings_page'), 'reading' );
}

Function print_settings_page(){ Include DirName(__FILE__).'/settings_page.php'; }

Function save_settings_page(){
// Check if there is a post request
If ( !Empty($_POST) && $_POST['option_page'] == 'reading' && $_POST['action'] == 'update' )
$settings = (Array) $_POST[self::get_setting_key()];
Else return;

// Store
update_option(self::get_setting_key(), $settings);
}

Function load_setting($key = Null, $default = False){
$arr_setting = (Array) get_option(self::get_setting_key());
If ($key == Null) return $arr_setting;
ElseIf (IsSet ($arr_setting[$key])) return $arr_setting[$key];
Else return $default;
}

Function add_meta_box(){
Add_Meta_Box( get_class($this), $this->t('Associate posts with this page'), Array($this, 'print_meta_box'), 'page', 'advanced', 'high' );
}

Function print_meta_box(){ Include DirName(__FILE__).'/meta_box.php'; }

Function save_meta_box($post_id){
// If this is an autosave we dont care
If ( Defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;

// Check if the user want to attach posts
If ( IsSet ($_POST[$this->get_setting_key()]) &&
!Empty($_POST[$this->get_setting_key()]) &&
!( Empty($_POST[$this->get_setting_key()]['category']) &&
Empty($_POST[$this->get_setting_key()]['tag']) &&
Empty($_POST[$this->get_setting_key()]['author']) &&
Empty($_POST[$this->get_setting_key()]['post']) )
)
{
$arr_settings = (Array) $_POST[$this->get_setting_key()];
update_post_meta ($post_id, $this->get_meta_key(), $arr_settings);
}
Else {
delete_post_meta ($post_id, $this->get_meta_key());
}

}

Function add_admin_header(){ ?>
<link type="text/css" rel="stylesheet" href="<?php echo $this->base_url?>/admin.css" />
<?php
}

Function field_name ($key){ return self::get_setting_key().'['.$key.']'; }

Function shortcode($attr){
Global $post;

// Convert $attr to an array
$attr = (Array) $attr;

// Check if there are association_settings
If ( !self::has_associated_posts() ) return False;

// Find the right template file
If (Is_File(get_template_directory().'/associated-posts.php')){
$template_file = get_template_directory().'/associated-posts.php';
}
ElseIf (Is_File(DirName(__FILE__).'/template.php')){
$template_file = DirName(__FILE__).'/template.php';
}

// Uses filter
$template_file = Apply_Filters('associated_posts_template', $template_file);

// Look whats the current post
If (Is_Object($post)) $this->current_post = clone $post;

// Use the template
Ob_Start();
Include $template_file;
$result = Ob_get_Contents();
Ob_End_Clean();

// Restore post data
If (Is_Object($this->current_post)) $post = clone $this->current_post;
Unset ($this->current_post);
setup_postdata($post);

// return code
return $result;
}

Function has_associated_posts($post_id = Null){
/*
This function is deprecated!
I will remove it in the next releases!
*/
$association = self::get_association_data($post_id);

// Check if there are settings
If ( Empty($association['category']) &&
Empty($association['tag']) &&
Empty($association['author']) &&
Empty($association['post'])
)
return False;
Else
return True;

}

Function get_association_data($post_id = Null){
If ($post_id == Null){
Global $post;
$post_id = $post->ID;
}

$meta = Array_Merge(Array(
'category_select_mode' => 'one',
'category' => Array(),
'tag_select_mode' => 'or_one',
'tag' => Array(),
'author_select_mode' => 'or',
'author' => Array(),
'post' => Array(),
'post_limit' => '',
'order_by' => 'date',
'order' => 'ASC'
), (Array) get_post_meta($post_id, self::get_meta_key(), True));

return $meta;
}

Function get_associated_posts ($post_id = Null){
// If there is no post_id we try to ready it
If ($post_id == Null) $post_id = get_the_id();

// If there is even no post_id we bail out
If (!$post_id) return False;

// read the associated category
$association = self::get_association_data($post_id);

// Filter posts
$arr_post_category = Array();
$arr_post_tag = Array();
$arr_post_author = Array();
$arr_post = Array();

// By Category
If (!Empty($association['category']))
If ($association['category_select_mode'] == 'or_one' || $association['category_select_mode'] == 'and_one')
$arr_post_category = self::get_post_ids_by_category($association['category'], 'or');
ElseIf ($association['category_select_mode'] == 'or_all' || $association['category_select_mode'] == 'and_all')
$arr_post_category = self::get_post_ids_by_category($association['category'], 'and');

// By Tag
If (!Empty($association['tag']))
If ($association['tag_select_mode'] == 'or_one' || $association['tag_select_mode'] == 'and_one')
$arr_post_tag = self::get_post_ids_by_tag($association['tag'], 'or');
ElseIf ($association['tag_select_mode'] == 'or_all' || $association['tag_select_mode'] == 'and_all')
$arr_post_tag = self::get_post_ids_by_tag($association['tag'], 'and');

// By Author
If (!Empty($association['author']))
If ($association['author_select_mode'] == 'or' || $association['author_select_mode'] == 'and')
$arr_post_author = self::get_post_ids_by_author($association['author']);


// Add to the selected posts
// Add Categories
If ($association['category_select_mode'] == 'or_one' || $association['category_select_mode'] == 'or_all')
$arr_post = Array_Merge ($arr_post, $arr_post_category);

// Add Tags
If ($association['tag_select_mode'] == 'or_one' || $association['tag_select_mode'] == 'or_all')
$arr_post = Array_Merge ($arr_post, $arr_post_tag);

// Add Author
If ($association['author_select_mode'] == 'or')
$arr_post = Array_Merge ($arr_post, $arr_post_author);


// Filter the selected posts
// Filter Categories
If ($association['category_select_mode'] == 'and_one' || $association['category_select_mode'] == 'and_all')
$arr_post = Array_Intersect ($arr_post, $arr_post_category);

// Filter Tags
If ($association['tag_select_mode'] == 'and_one' || $association['tag_select_mode'] == 'and_all')
$arr_post = Array_Intersect ($arr_post, $arr_post_tag);

// Filter Author
If ($association['author_select_mode'] == 'and')
$arr_post = Array_Intersect ($arr_post, $arr_post_author);

// Add the additional posts
$arr_post = Array_Merge ($arr_post, (Array) $association['post']);

// There are no posts we have to care about
If (Empty($arr_post)) return False;

return new WP_Query(Array(
'post__in' => $arr_post,
'posts_per_page' => $association['post_limit'] == '' ? -1 : IntVal($association['post_limit']),
'orderby' => $association['order_by'],
'order' => $association['order'],
'caller_get_posts' => 1
));
}

Function get_post_ids_by_category ($arr_category, $operator = 'OR'){
$arr_category = (Array) $arr_category;
$operator = StrToLower ($operator);
$result = Array();

// Get the posts
If ($operator == 'or'){
ForEach ($arr_category AS $category){
$query = New WP_Query(Array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'category__in' => $arr_category
));
$result = Array_Merge ($result, self::extract_post_ids($query));
}
$result = Array_Unique ($result);
}
ElseIf ($operator == 'and'){
$query = New WP_Query(Array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => 1,
'category__and' => $arr_category
));
$result = self::extract_post_ids($query);
}

return $result;
}

Function get_post_ids_by_tag ($arr_tag, $operator = 'OR'){
$arr_tag = (Array) $arr_tag;
$operator = StrToLower ($operator);
$result = Array();

// Get the posts
If ($operator == 'or'){
ForEach ($arr_tag AS $tag){
$query = New WP_Query(Array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => 1,
'tag__in' => $arr_tag
));
$result = Array_Merge ($result, self::extract_post_ids($query));
}
$result = Array_Unique ($result);
}
ElseIf ($operator == 'and'){
$query = New WP_Query(Array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => 1,
'tag__and' => $arr_tag
));
$result = self::extract_post_ids($query);
}

return $result;
}

Function get_post_ids_by_author($arr_author_id){
$arr_author_id = (Array) $arr_author_id;
$result = Array();

// Get all posts by these authors
ForEach ($arr_author_id AS $author_id){
$query = New WP_Query(Array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => 1,
'author' => $author_id
));
$result = Array_Merge ($result, self::extract_post_ids($query));
}

// Clean the array
return Array_Unique ($result);
}

Function extract_post_ids($wp_query){
$result = Array();

If ($wp_query && Is_Array($wp_query->posts)){
ForEach ($wp_query->posts AS $p)
$result[] = $p->ID;
}

return $result;
}

Function filter_content($content){
$template_file = Apply_Filters('associated_posts_auto_append', True);

// Append the ShortCode to the Content
If ( StrPos($content, '[associated_posts]') === False && // Avoid double inclusion of the ShortCode
StrPos($content, '[associated_posts ') === False && // Without closing bracket to find ShortCodes with attributes
Apply_Filters('associated_posts_auto_append', True) // You can use this filter to control the auto append feature
)
// Add the ShortCode to the current content
return $content . "\r\n[associated_posts]\r\n";
Else
// the shortcode is already in the content / the filter says no
return $content;
}

Function get_post_thumbnail($post_id = Null, $size = 'thumbnail'){
/* Return Value: An array containing:
$image[0] => attachment id
$image[1] => url
$image[2] => width
$image[3] => height
*/
If ($post_id == Null) $post_id = get_the_id();

If (Function_Exists('get_post_thumbnail_id') && $thumb_id = get_post_thumbnail_id($post_id) )
return Array_Merge ( Array($thumb_id), wp_get_attachment_image_src($thumb_id, $size) );
ElseIf ($arr_thumb = self::get_post_attached_image($post_id, 1, 'RAND', $size))
return $arr_thumb[0];
Else
return False;
}

Function get_post_attached_image($post_id = Null, $number = 1, $orderby = 'RAND', $image_size = 'thumbnail'){
If ($post_id == Null) $post_id = get_the_id();
$number = IntVal ($number);
$arr_attachment = get_posts (Array( 'post_parent' => $post_id,
'post_type' => 'attachment',
'numberposts' => $number,
'post_mime_type' => 'image',
'orderby' => $orderby ));

// Check if there are attachments
If (Empty($arr_attachment)) return False;

// Convert the attachment objects to urls
ForEach ($arr_attachment AS $index => $attachment){
$arr_attachment[$index] = Array_Merge ( Array($attachment->ID), wp_get_attachment_image_src ($attachment->ID, $image_size));
/* Return Value: An array containing:
$image[0] => attachment id
$image[1] => url
$image[2] => width
$image[3] => height
*/
}

return $arr_attachment;
}

Function get_authors(){
$arr_author = Array();

ForEach ( (Array) get_author_user_ids() AS $author_id)
$arr_author[] = get_userdata( $author_id );

If (Empty($arr_author))
return False;
Else
return $arr_author;
}

Function get_all_posts(){
$post_query = new WP_Query(Array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'caller_get_posts' => 1
));

return $post_query->posts;
}

} /* End of Class */
New wp_plugin_associate_posts_and_pages();
} /* End of If-Class-Exists-Condition */
/* End of File */

grazie
http://www.vampirediaries-love.net/
Avatar utente
Martina Stella
Senior Member
Senior Member
 
Messaggi: 354
Iscritto il: ven gen 16, 2009 3:02 pm
Località: Treviso, Veneto

Torna a Sviluppo Web

Chi c’è in linea

Visitano il forum: Nessuno e 0 ospiti

Powered by phpBB © 2002, 2005, 2007, 2008 phpBB Group
Traduzione Italiana phpBB.it

megalab.it: testata telematica quotidiana registrata al Tribunale di Cosenza n. 22/09 del 13.08.2009, editore Master New Media S.r.l.; © Copyright 2008 Master New Media S.r.l. a socio unico - P.I. 02947530784. GRUPPO EDIZIONI MASTER Spa Tutti i diritti sono riservati. Per la pubblicità: Master Advertising