السلام عليكم
رجاء إخواني أريد كود لعرض كلمة جديد مع عنوان المقالة
وتختفي لفترة محدودة
فقد وجدت إضافة لكن لا تتوفر على مدة العرض والكلمة يجب إدخالها في كل مرة وأخرى بها أخطاء ولا تضهر إلا عند الدخول للموضوع
كود الإضافة الأولى
الرجاء مساعدتي في التعديا عليها لعرض لمدة 10 أيام
\[code\]<?php
/\*
Plugin Name: Post Badges
Plugin URI: https://wordpress.org/plugins/templatic-badge
Description: This add-on allows you to display a badge on your listings , where you can set label and color for the badge.
Version: 1.0
Author: Templatic
Author URI: https://templatic.com/
\*/
/\* added .mo file for translation \*/
$locale = get\_locale();
load\_textdomain( 'templatic\_badge', plugin\_dir\_path( \_\_FILE\_\_ ).'languages/'.$locale.'.mo' );
/\* added farbtastic script and css while adding badges from backend \*/
add\_action('admin\_enqueue\_scripts','tmpl\_badge\_admin\_head\_script',99);
function tmpl\_badge\_admin\_head\_script(){
wp\_enqueue\_script('farbtastic');
wp\_enqueue\_style('farbtastic');
}
register\_activation\_hook(\_\_FILE\_\_, 'tmpl\_badge\_activate');
/\* while activation save variable to show activation message \*/
function tmpl\_badge\_activate() {
add\_option('tmpl\_badge\_activate\_msg', 'y');
}
/\* This function display admin notice to activate templatic-badge plugin, if they first activated \*/
add\_action('admin\_notices','tmpl\_badge\_admin\_notices',99);
function tmpl\_badge\_admin\_notices(){
if (get\_option('tmpl\_badge\_activate\_msg') == 'y') {
echo '<div class="updated"><p>'. \_\_('Templatic - Badges plugin is activated successfully. Badges can be added from Add Post page in backend from "Templatic Badge" section.','templatic\_badge') . '</p></div>';
delete\_option('tmpl\_badge\_activate\_msg');
}
}
/\* Class for templatic badges where badges are saved and shown besides title \*/
class templaticBadges
{
/\* call default construtor \*/
function \_\_construct()
{
/\* action to show metabox at backend \*/
add\_action('admin\_init',array($this,'tmpl\_badge\_meta\_box'));
/\* save badge in post meta table \*/
add\_action( 'save\_post', array( $this, 'tmpl\_badge\_save\_post' ), 1, 2 );
}
/\* call badge metabox \*/
function tmpl\_badge\_meta\_box(){
global $post;
/\* names or objects \*/
$output = 'objects';
$args = array();
/\* names or objects, note names is the default \*/
$output = 'names';
/\* 'and' or 'or' \*/
$operator = 'and';
$post\_types = get\_post\_types( $args, $output, $operator );
$exclude\_post\_type = apply\_filters('tmpl\_badge\_unset\_post\_type',array('page','attachment','revision','nav\_menu\_item'));
/\* loop for post type to show post detail template \*/
foreach ( $post\_types as $post\_type ) {
if(in\_array($post\_type,$exclude\_post\_type))
continue;
/\*show single page template for custom post type\*/
add\_meta\_box( 'templatic\_badge', \_\_( 'Templatic Badge', 'templatic\_badge' ), array( $this,'tmpl\_badge\_meta\_box\_content'), $post\_type, 'side','high',$post );
}
}
/\* display metabox for each post type \*/
function tmpl\_badge\_meta\_box\_content(){
global $post;
$newbadge\_title=get\_post\_meta($post->ID,'newbadge\_title',true);
$newbadge\_color=get\_post\_meta($post->ID,'newbadge\_color',true);
$newbadge\_color=($newbadge\_color!='')?$newbadge\_color:'#';
?>
<input type="hidden" name="tmpl\_noncename" id="tmpl\_noncename" value="<?php echo wp\_create\_nonce( plugin\_basename( \_\_FILE\_\_ ) ); ?>" />
<ul class="badge\_list">
<li>
<label><strong><?php echo \_e('Badge Title','templatic\_badge');?></strong></label><span><input type="text" name="newbadge\_title" value="<?php echo $newbadge\_title?>" /></span>
<p class="description"><?php \_e('This title will appear as a badge on your listings, detail pages and widgets.','templatic\_badge');?></p>
</li>
<li>
<label><strong><?php echo \_e('Color','templatic\_badge');?></strong></label>
<span><input type="text" name="newbadge\_color" value="<?php echo $newbadge\_color;?>" id="newbadge\_color\_picker" /></span>
<a><span class="dashicons dashicons-dismiss"></span></a>
<div class="farbtastic\_color" id="color\_newbadge\_color\_picker" name="newbadge\_color\_picker" style="display:none" >
</div>
<p class="description"><?php \_e('Select color for your new badge.','templatic\_badge');?></p>
</li>
<script type="text/javascript">
jQuery(document).ready(function($){
jQuery("#color\_newbadge\_color\_picker").farbtastic("#newbadge\_color\_picker");
jQuery(document).on( 'click focus','#newbadge\_color\_picker', function(e) {
jQuery('\[name="newbadge\_color\_picker"\]').css('display', 'block');
jQuery('#close\_newbadge\_color\_picker').css('display', 'block');
return false;
});
jQuery(document).on( 'click focus','#close\_newbadge\_color\_picker', function(e) {
jQuery('\[name="newbadge\_color\_picker"\]').css('display', 'none');
jQuery('#close\_newbadge\_color\_picker').css('display', 'none');
return false;
});
});
</script>
<?php
}
/\* Save Directory NewBadge filed save \*/
function tmpl\_badge\_save\_post($post\_id,$post){
/\*
\* Verify this came from the our screen and with proper authorization,
\* because save\_post can be triggered at other times
\*/
if ( ! wp\_verify\_nonce( $\_POST\['tmpl\_noncename'\], plugin\_basename( \_\_FILE\_\_ ) ) )
return $post->ID;
if ( defined( 'DOING\_AJAX' ) && DOING\_AJAX ) {
return ;
}
/\* names or objects \*/
$output = 'objects';
$args = array();
/\* names or objects, note names is the default \*/
$output = 'names';
/\* 'and' or 'or' \*/
$operator = 'and';
$post\_types = get\_post\_types( $args, $output, $operator );
if(!empty($post\_types) && in\_array($\_POST\['post\_type'\],$post\_types)){
update\_post\_meta($post\_id,'newbadge\_title',$\_POST\['newbadge\_title'\]);
update\_post\_meta($post\_id,'newbadge\_color',$\_POST\['newbadge\_color'\]);
}
}
} /\* end class \*/
add\_filter('the\_title','tmpl\_badge\_tag',10,2);
/\* to show badge beside post title where we have used wordpress the\_title \*/
function tmpl\_badge\_tag($title,$post\_id){
global $post;
if(!is\_admin())
{
$newbadge\_title=get\_post\_meta($post\_id,'newbadge\_title',true);
$newbadge\_title=($newbadge\_title!="")? $newbadge\_title : '';
$newbadge\_color=get\_post\_meta($post\_id,'newbadge\_color',true);
$tmpl\_display\_badge = '';
if($newbadge\_title!=''){
$tmpl\_display\_badge = '<span class="badge-status" style="background:'. $newbadge\_color.'">'. $newbadge\_title.'</span> ';
}
return apply\_filters('tmpl\_title\_badge',$title.$tmpl\_display\_badge);
}
else
return $title;
}
$templ = new templaticBadges(); // go
/\* include css in for badge \*/
add\_action('wp\_head','tmpl\_badge\_wp\_footer');
function tmpl\_badge\_wp\_footer(){
?>
<style type="text/css">
.badge-status { display:inline; font-size:11px; color:#fff; padding:3px 5px; margin:5px; position: relative; top:-7px;
-webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px;}
.widget .badge-status {top:-3px; font-size:10px; }
</style>
<?php
}\[/code\]