I have this tag cloud, which is currently set to show the most popular item first with the use of (line 205):
// arsort($array_end);
which reverses the array. If i leave this out it shows the list alphabetically.
I would like to have the results shown randomly. I thought of php-shuffle, but i don't know how to go about it. Appreciate if someone could help me out here, Cheers!
See php below (also uploaded php here as .txt):
//activate plugin WP function
//Checking search meter dependencies
global $wpdb, $table_prefix;
$sql = "SHOW TABLES LIKE '{$table_prefix}searchmeter_recent'";
$results = $wpdb->get_results($sql);
if (!$wpdb->num_rows )
{
die( '<p>This plugin will not work unless Search Meter plugin is installed and activated.</p>' );
}
register_activation_hook( __FILE__, 'initializeSearchTagCloud');
//activat plugin WP function
register_deactivation_hook( __FILE__, 'deactivateSearchTagCloud');
//set initial values when the plugin is activated
function initializeSearchTagCloud()
{
$search_tag_cloud=new searchTagCloud();
$search_tag_cloud->initializeSearchTagCloud();
}
//delete DB options when the plugin is activated
function deactivateSearchTagCloud() {
delete_option("searchTagCloudOption");
}
class searchTagCloud
{
public $widgetText;
public $numberSearches;
public $max_size;
public $min_size;
public $days_to_display;
var $error;
//constuctor function
function __construct()
{
$this->min_size=12;
$this->max_size=32;
$this->widgetText = 'What people is searching?';
$this->total_tags=10;
$this->show_author_credit=0;
$this->days_to_display=30;
//the size of the tag cloud is missed
}
//initialize options
//size of the smallest tag
//maximum size of the biggest tag
//Personalized text for the tag cloud
//how many links to display
function initializeSearchTagCloud()
{
global $wpdb, $table_prefix;
$wpdb->query("ALTER TABLE `{$table_prefix}searchmeter_recent` ADD COLUMN visible INT( 1 ) NOT NULL DEFAULT '1'");
$initializeOptions = array(
"min_size" => $this->min_size,
"max_size" => $this->max_size,
"total_tags" => $this->total_tags,
"widgetText" => $this->widgetText,
"days_to_display" => $this->days_to_display,
"show_author_credit" => $this->show_author_credit,
);
add_option("searchTagCloudOption", $initializeOptions, '', 'yes');
//select recent searched terms
}
//get DB options for the Search Tag Cloud
function getSearchTagCloudOptions()
{
$myOptions = get_option('searchTagCloudOption');
$this->min_size=$myOptions['min_size'];
$this->max_size=$myOptions['max_size'];
$this->widgetText=$myOptions['widgetText'];
$this->total_tags=$myOptions['total_tags'];
$this->days_to_display=$myOptions['days_to_display'];
$this->show_author_credit=$myOptions['show_author_credit'];
}
//set Search Tag Cloud class values
function setSearchTagCloudValues($min_size,$max_size,$total_tags,$widgetText,$show_author_credit,$days_to_display)
{
$this->min_size=$min_size;
$this->max_size=$max_size;
$this->widgetText=$widgetText;
$this->total_tags=$total_tags;
$this->show_author_credit=$show_author_credit;
$this->days_to_display=$days_to_display;
}
//update Search Tag Cloud class values and DB options
function updateSearchTagCloud($array_post)
{
global $wpdb, $table_prefix;
$this->setSearchTagCloudValues($array_post['min_size'],$array_post['max_size'],$array_post['total_tags'],$array_post['widgetText'],$array_post['show_author_credit'],$array_post['days_to_display']);
//set the new options in the database
update_option("searchTagCloudOption", $array_post, '', 'yes');
//I set all to visible
$wpdb->query("UPDATE `{$table_prefix}searchmeter_recent` SET visible=1");
if(is_array($array_post['checkbox_visible']))
{
foreach($array_post['checkbox_visible'] as $index=>$value)
$wpdb->query("UPDATE `{$table_prefix}searchmeter_recent` SET visible=0 WHERE terms = '{$value}'");
}
return __("Options Saved Correctly");
}
//Function to select from search meter tables in the database the most common searches.
function select_searches_for_tagcloud()
{
// List the most recent successful searches.
global $wpdb, $table_prefix;
$this->getSearchTagCloudOptions();
$count = intval($this->total_tags);
//first I need to know how many invisible tags we have
//select terms, COUNT( * ) AS total FROM `wp_searchmeter_recent` WHERE datetime>='2010-07-05' GROUP BY `terms` LIMIT 0,15
//$datebeginning = date()-dÌas
$datebeginning = date('Y-m-d', mktime(0, 0, 0, date("m"),date("d")-$this->days_to_display, date("Y")));
$tags = $wpdb->get_results(
//select recent searched terms
" SELECT terms, visible, COUNT( * ) AS total
FROM `{$table_prefix}searchmeter_recent`
WHERE datetime>='{$datebeginning}' AND
hits>0 AND
visible=1
GROUP BY `terms`
LIMIT {$count}");
return $tags;
}
function selectPopularSearchesforAdmin()
{
// List the most recent successful searches.
global $wpdb, $table_prefix;
$this->getSearchTagCloudOptions();
$count = intval($this->total_tags);
//first I need to know how many invisible tags we have
//select terms, COUNT( * ) AS total FROM `wp_searchmeter_recent` WHERE datetime>='2010-07-05' GROUP BY `terms` LIMIT 0,15
//$datebeginning = date()-dÌas
$datebeginning = date('Y-m-d', mktime(0, 0, 0, date("m"),date("d")-$this->days_to_display, date("Y")));
$invisible_tags = $wpdb->get_results(
" SELECT terms, COUNT( * ) AS total
FROM `{$table_prefix}searchmeter_recent`
WHERE visible=1 AND
`datetime`>='{$datebeginning}' AND
hits>0
GROUP BY `terms`
LIMIT {$count}");
// I have to show the tags plus the invisible ones
$count = $count + count($invisible_tags);
$tags = $wpdb->get_results(
//select recent searched terms
" SELECT terms, visible, COUNT( * ) AS total
FROM `{$table_prefix}searchmeter_recent`
WHERE datetime>='{$datebeginning}' AND
hits>0
GROUP BY `terms`
LIMIT {$count}");
return $tags;
}
//function that creates the tag cloud and prints it.
function popular_searches_tag_cloud($args)
{
$results=$this->select_searches_for_tagcloud();
if(count($results)>0)
{
foreach($results as $index)
{
$array_end[$index->terms]=$index->total;
}
// arsort($array_end);
// largest and smallest array values
$max_qty = max(array_values($array_end));
$min_qty = min(array_values($array_end));
// find the range of values
$spread = $max_qty - $min_qty;
if ($spread == 0) { // we don't want to divide by zero
$spread = 1;
}
// set the font-size increment
$step = ($this->max_size - $this->min_size) / ($spread);
//set the counter for the loop at 0
$counter=0;
// loop through the tag array
if(count($array_end)>0)
{
$html='<div class="search-tag-cloud">';
$html.='<h2>'.$this->widgetText.'</h2>';
foreach ($array_end as $key => $value)
{
if($counter<=$this->total_tags)
{
$counter++;
// calculate font-size
// find the $value in excess of $min_qty
// multiply by the font-size increment ($size)
// and add the $min_size set above
$size = round($this->min_size + (($value - $min_qty) * $step));
$html.= '<a href="?s=' . $key . '" style="font-size: ' . $size . 'px"
title="' . $key . '">' . $key . '</a> ';
}
else
break;
}
if($this->show_author_credit==1)
$html.='<div id="search-tag-cloud"><p style="text-align:right"><small>WP plugin by Marketing Online</small></p></div>';
$html.='</div>';
echo $html;
}
}
}
}
/*end class--------------------------------*/
//setting the admin page
//create admin->settings page
//create Settings Section to configure plugin values
if (is_admin() ){ // admin actions
add_action('set_twitter_keyword_values','set_twitter_keyword');
add_action('admin_menu','admin_setSearchTagCloud');
add_action('admin_init','searchTagCloudSettings' );
} else {
// non-admin enqueues, actions, and filters
}
//adding the page in the admin section
function admin_setSearchTagCloud() {
add_options_page('Popular Searches Tag Cloud Options', 'Popular Searches Tag Cloud', 8,__FILE__, 'searchTagCloudOptions');
}
//register form fields
function searchTagCloudSettings() { // whitelist options
register_setting('search-tag-cloud-options', 'widgetText', 'wp_filter_nohtml_kses');
register_setting('search-tag-cloud-options', 'max_size', 'checkValueisInt');
register_setting('search-tag-cloud-options', 'min_size', 'checkValueisInt');
register_setting('search-tag-cloud-options', 'total_tags', 'checkValueisInt');
register_setting('search-tag-cloud-options', 'checkbox_visible');
register_setting('search-tag-cloud-options', 'show_author_credit', 'checkValueisInt');
register_setting('search-tag-cloud-options', 'days_to_display', 'checkValueisInt');
}
function searchTagCloudOptions()
{
$html= '<div class="wrap">';
$html= '<form method="post">';
settings_fields('search-tag-cloud-options');
$html.= '<h2>'. __("Popular Searches Tag Cloud Options: Manage Options").'</h2>';
if($_POST['type-submit']=='Y')
{
$message=updateSearchTagCloudForm($_POST);
if($message!='')
$html.= '<div class="error"><p><strong>'.$message.'</strong></p></div>';
else
$html.= '<div class="updated"><p><strong>'.__("Options Saved").'</strong></p></div>';
$myOptions=get_option('searchTagCloudOption');
}
else
$myOptions=get_option('searchTagCloudOption');
$html.= '<label for="newpost-edited-text">'.__('Set the header for the Popular Searches Tag Cloud to be visible: ').'</label>';
$html.= '<input type="text" name="widgetText" size="40" maxlength="150" value="'.$myOptions['widgetText'].'" /><br /><br />';
$html.= '<label for="newpost-edited-text">'.__('Size of the biggest tag: ').'</label>';
$html.= '<input type="text" name="max_size" size="10" maxlength="3" value="'.$myOptions['max_size'].'" /><br /><br />';
$html.= '<label for="newpost-edited-text">'.__('Size of the smallest tag: ').'</label>';
$html.= '<input type="text" name="min_size" size="10" maxlength="3" value="'.$myOptions['min_size'].'" /><br /><br />';
$html.= '<label for="newpost-edited-text">'.__('Number of searches to display: ').'</label>';
$html.= '<input type="text" name="total_tags" size="10" maxlength="3" value="'.$myOptions['total_tags'].'" /><br /><br />';
$html.= '<label for="newpost-edited-text">'.__('You want to show searches from the last : ').'</label>';
$html.= '<input type="text" name="days_to_display" size="10" maxlength="3" value="'.$myOptions['days_to_display'].'" /> days<br /><br />';
$html.=getMostPopularSearchesAdmin($results, 15, false);
$html.= '<br /><br /><label for="newpost-edited-text">'.__('Display developer credits in the Widget: ').'</label>';
$html.= '<input type="checkbox" name="show_author_credit" value="1" ';
if ($myOptions['show_author_credit']==1)
$html.='checked';
$html.='/><br /><br />';
$html.= '<input type="hidden" name="type-submit" value="Y">';
$html.= '<br><input type="submit" class="button-primary" value="'.__('Save Options').'" />';
//here I need the list of all searches, order by total
$html.= '</form>';
$html.= '</div>';
echo $html;
}
//function to show common searches to edit in the admin page. Completes the admin form.
function getMostPopularSearchesAdmin(){
$searchcloud=new searchTagCloud();
$results=$searchcloud->selectPopularSearchesforAdmin();
if (count($results)) {
$html='<table cellpadding="3" cellspacing="2">';
$html.='<tbody>';
$html.='<tr class="alternate"><th class="left">Term</th><th>Set not Visible</th>';
if ($do_include_successes) {
$html.='<th>Results</th>';
}
$html.='</tr>';
$class= '';
$counter=0;
foreach ($results as $result) {
$html.='<tr class="'.$class.'">';
$html.='<td>'.htmlspecialchars($result->terms).'</td>';
$html.='<td align="center"><input type="checkbox" name="checkbox_visible['.$counter.']" value="'.$result->terms.'" ';
if ($result->visible==0)
$html.='checked';
$html.='/>';
$html.='</td>';
$html.='</tr>';
$class = ($class == '' ? 'alternate' : '');
$counter++;
}
$html.='</tbody>';
$html.='</table>';
} else {
$html.='<p>No searches recorded for this period.</p>';
}
return $html;
}
//This functions checks the data send by the form and calls the update the option.
function updateSearchTagCloudForm($array)
{
$message='';
$search_tag_cloud=new searchTagCloud();
//check values before inserting into DB
$message=checkNumbers($array['max_size']);
$message.=checkNumbers($array['min_size']);
$message.=checkNumbers($array['total_tags']);
$message.=checkSearchCloudWidgetText($array['widgetText']);
$message.=checkNumbers($array['days_to_display']);
if($array['show_author_credit'])
$message.=checkNumbers($array['show_author_credit']);
if($message!='')
return $message;
if($message=='')
{
$search_tag_cloud->updateSearchTagCloud($array);
}
}
//checking function for the form fields functions in the admin page
function checkNumbers($number)
{
if(!intval( $number ))
return __("The field maximum size and minimum size have to be numeric<br />");
elseif($number>100)
return __("Maximum size and minimum size have to be smaller than 100<br />");
else
return "";
}
//checking function for the form fields functions in the admin page
function checkSearchCloudWidgetText($widgetText)
{
if(strlen($widgetText)>150)
{
return __("You are not allowed to include more than 150 characters in the Widget Text<br />");
}
return "";
}
//Widgetizing the plugin functions
function setSearchTagCloudPlugin()
{
register_sidebar_widget(__('Popular Searches Tag Cloud'), 'callSearchTagCloud');
register_widget_control(__('Popular Searches Tag Cloud'), 'callSearchTagCloud', 200, 200 );
}
add_action("plugins_loaded", "setSearchTagCloudPlugin");
//function to initailize the class. Called from sidebar.php, it checks dependencies from the search meter plugin.
function callSearchTagCloud()
{
global $wpdb, $table_prefix;
$sql = "SHOW TABLES LIKE '{$table_prefix}searchmeter_recent'";
$results = $wpdb->get_results( $sql );
if ( ! $wpdb->num_rows )
{
die( '<p>This plugin will not work unless Search Meter plugin is installed and activated. -- widget</p>' );
}
else
{
$search_tag_cloud=new searchTagCloud();
$search_tag_cloud->initializeSearchTagCloud();
}
$searchcloud=new searchTagCloud();
$searchcloud->popular_searches_tag_cloud($tags,$args);
}
function setSearchTagCloudControl()
{
echo '<p><label for="myHelloWorld-WidgetTitle">To configure options go to "Settings > Popular Searches Tag Cloud" in this admin panel</label></p>';
}
Use the shuffle function:
This function shuffles (randomizes the order of the elements in) an array.
A little below
// arsort($array_end);`
You got this code:
foreach ($array_end as $key => $value)
{
Replace it with this:
$array_end_keys = array_keys($array_end);
shuffle($array_end_keys);
foreach ($array_end_keys as $key)
{
$value = $array_end[$key];
Related
<?php
/**
* Plugin Name: Display UserID
* Plugin URI: http://www.sitecrafters.pro/plugins/measurement-tracker.zip
* Description: The very seventh plugin that I have ever created.
* Version: 1.10
* Author: Cody King
* Author URI: http://sitecrafters.pro
*/
/**
* #snippet Display UserID
* #author Cody King
* #compatible Wordpress 6.0
*/
function show_form(){
$user_id = get_current_user_id();
echo '<form method="GET">'; // printing form tag
echo '<input type="text" name="inches">';
echo '<input type="submit" name="send_btn" value="Submit">';
echo '</form>';
if (isset($_GET['send_btn'])) { // checking is form was submitted then accessing to value
$bicep = $_GET['inches'];
if ($user_id == 0) {
// The user ID is 0, therefore the current user is not logged in
return; // escape this function, without making any changes to database
}
update_user_meta($user_id,'_bicep_measurement',$bicep);
return "Today your bicep is: $bicep inches!";
}
}
add_shortcode('show_form','show_form');
function checkBiceps(){
$user_id = get_current_user_id();
$bicep = get_user_meta($user_id,'_bicep_measurement',true);
return "Your bicep was: $bicep inches last time";
}
add_shortcode('check_biceps','checkBiceps');
?>
This is a plugin I'm making to track body part measurements for WordPress users. I have gotten the shortcode to work, and it makes a functional input box... Up in the top corner.
For some reason, this form is being displayed in the upper left corner instead of inline, where I put the shortcode. What am I doing wrong here?
I admit, I'm new to this programming language and making Wordpress plugins but I want to learn.
Like this:
<?php
function show_form()
{
$user_id = get_current_user_id();
$str = "";
$str .= '<form method="GET">'; // printing form tag
$str .= '<input type="text" name="inches">';
$str .= '<input type="submit" name="send_btn" value="Submit">';
$str .= '</form>';
if (isset($_GET['send_btn'])) { // checking is form was submitted then accessing to value
$bicep = $_GET['inches'];
if ($user_id == 0) {
// The user ID is 0, therefore the current user is not logged in
return; // escape this function, without making any changes to database
}
update_user_meta($user_id, '_bicep_measurement', $bicep);
return "Today your bicep is: $bicep inches!";
}
return $str;
}
add_shortcode('show_form', 'show_form');
I building on top of an existing PHP based application to ability to update menu items name and prices.
I have generated a dynamic form which is populated with the results form the database. The idea is that the user can update the item name or price to update the information in the database.
The form works fine, but I am having dome trouble getting the info out of the form. each Item has a separate ID so I need to essentially do a foreach through the form and call the update function each time with the respective item id.
I can handle the DB side of things fine, but the application I am building on has a 'getInput' function to check input exists and to get the input form the form and I would like to use this.
This is the getInput function:
public static function exists($type = 'post') {
switch($type) {
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get';
return (!empty($_GET)) ? true : false;
break;
default:
return false;
break;
}
}
public static function get($item) {
if(isset($_POST[$item])) {
return $_POST[$item];
} else if(isset($_GET[$item])) {
return $_GET[$item];
}
return '';
}
}
The problem I have is when calling this function it only returns the last item form the form. Is there a way i can iterate though the form and get each item?
This is the dynamic form and the getInput code so far:
$menuItems = DB::getInstance()->get('menu_items', array('cat_id', '=', $cat_id ));
if($menuItems->count()) {
echo '<form class="updateMenu" action="" method="post">';
echo '<table class="gridtable gridtableMenu">';
echo '<tr><th>Item Name</th><th>Item Price</th></tr>';
foreach($menuItems->results() as $item) {
echo '<tr>';
echo '<td class="menu-name"><input type="text" name="itemName" value="' . $item->item_name . '" required></td>';
echo '<td class="menu-price"><input type="number" step="any" name="itemPrice" value="' . $item->item_price . '" required></td>';
echo '<input type="hidden" name="id" value="' . $item->id . '">';
echo '</tr>';
}
echo '</table>';
echo '<input type="submit" name="updateMneu" value="Update Menu">';
echo '</form>';
} else {
echo '<div class="error">No items have been added to this menu</div>';
}
} // close categories foreach
} // close if category set
if(isset($_POST['updateMneu'])) {
echo Input::get('id'), '</br>';
echo Input::get('itemName'), '</br>';
echo Input::get('itemPrice'), '</br>';
} //close if isset updateMenu If
So I would like a foreach I think around this section:
if(isset($_POST['updateMneu'])) {
echo Input::get('id'), '</br>';
echo Input::get('itemName'), '</br>';
echo Input::get('itemPrice'), '</br>';
//update ite in the database, and move to gthe next item.
} //close if isset updateMenu If
I will handle data validation and what not later on.
As posted by 'noobHere' the answer was to set the input types name as arrays. e.g. name="itemName[]" instead of name="itemName"
I have a list of favorite cars which i have added to each favorite car a checkbox for letting the user to remove the favorite car from his favorite car list. The problem is that the checkbox is working in a different way: If I check any car (1st, second.. last or multiple cars) and after hit submit the car that will get removed is the last one added instead of removing the selected one. If I check multiple cars, happens same thing, removes only the last car added.
PHP
public function GetFavoriteCars() {
include("inc/membersite_config.php");
$email = $fgmembersite->UserEmail(); // this is how I take the e-mail of the
global $base_path;
$FavoriteCars = $this->QueryResult("SELECT * FROM favoritecar WHERE email='$email'");
if (count($FavoriteCars)) {
$mystring='http://';
echo '<form action="" class="deletebutton" method="post">';
echo '<input type="submit" name="deletebtn" id="deletebtn" value="Submit">';
echo '<div class="roster_slideri-login">';
foreach ($FavoriteCars as $FavoriteCar) {
$carlink = $FavoriteCar->favoritecarlink;
echo '<div class="car-info-col-login">';
echo '<input type="checkbox" name="checkbox" value="'.$carlink.'" class="checkbox-login">';
$val=strpos($FavoriteCar->favoritecarimg,$mystring);
if ($val !== false) {
if($FavoriteCar->favoritecarimg!='') {
echo '<a href="'.$base_path.'detail-page_'.$FavoriteCar->favoritecarlink.'">';
echo '<img src="'.$FavoriteCar->favoritecarimg.'" alt="'.$FavoriteCar->favoritecartitle.'" width="160" height="120" />';
echo '</a>';
echo '<div class="name">'.substr($FavoriteCar->favoritecartitle,0,20).'</div>';
echo '</div>'; //car-info-col-login
}
} else {
echo '<a href="'.$base_path.'detail-page_'.$FavoriteCar->favoritecarlink.'">';
echo '<img src="'.$base_path.'uploads/no-img.jpg" alt="'.$FavoriteCar->favoritecartitle.'" width="160" height="120" />';
echo '</a>';
echo '<div class="name">'.substr($FavoriteCar->favoritecartitle,0,20).'</div>';
echo '</div>';
}
}
echo '</form>';
if (isset($_POST["checkbox"])) {
$this->QueryResult("DELETE from favoritecar WHERE email='$email' AND favoritecarlink='$carlink'");
echo '<script type="text/javascript">alert("Car had been deleted");</script>';
}
echo '</div>'; // div roster_slideri-login
}
}
Explaning:
$email = $fgmembersite->UserEmail(); - this is how I take the e-mail of the current logged in user. It will echo "email_of_logged_in_user#domain.com"
QueryResult is a custom function that looks like this. I usually use it for SELECTING purposes but it seams that is working for deleting purposes too.
abstract class DBDetails {
protected $link = NULL;
protected function connector() {
global $DBHOSTNAME;
global $DBUSERNAME;
global $DBPASSWORD;
global $DBNAME;
$this->link = mysqli_connect($DBHOSTNAME, $DBUSERNAME, $DBPASSWORD, $DBNAME) or die("Can't connect to MySQL server on localhost");
}
protected function close() {
mysqli_close($this->link);
}
}
abstract class N2 extends DBDetails {
public function QueryResult($strQuery) {
$this->connector();
$query = mysqli_query($this->link, $strQuery);
$arr = array();
if ($query) {
while ($result = mysqli_fetch_object($query)) {
array_push($arr, $result);
}
}
$this->close();
return $arr;
}
}
Expected output
When I check the checkbox of a car, it should delete only that car. If I check the checkboxes of multiple cars, should delete the specific cars that I checked.
Please help, I am quite a noob in checkboxes. I have checked lots of questions from here, but did not find my answer.
In this line :
echo '<input type="checkbox" name="checkbox" value="'.$carlink.'" class="checkbox-login">';
--------------
When using multiple checkboxes with same name , you would need to include [] in the name :
echo '<input type="checkbox" name="checkbox[]" value="'.$carlink.'" class="checkbox-login">';
----------------
Then $_POST["checkbox"] will be an array and you can use foreach on it to get all the checked values .
if( isset( $_POST["checkbox"] ) )
{
foreach( $_POST["checkbox"] as $value )
{
/* $value contains $carlink */
echo $value; // For test purpose
/* Sanitize and use it to identify and delete the corresponding row */
}
}
( Rather than name="checkbox[]" it might be better to choose another name . )
i am using a WP plugin to auto generate keywords and description for my site,
it is a single page Plugin, i want to modify it to work as i want, i am pasting whole code of php file:
<?php
/*
Plugin Name: Meta Keywords Generator
Plugin URI: http://home.techphernalia.com/2011/09/meta-keywords-generator/
Description: This plugin helps your SEO by adding meta keywords tag to each page, post, archive (category, tag, date, day and year). Now it also allows you to specify common keywords to be included on every web page. Plugin from one of the best coder Durgesh Chaudhary. For any support just leave your question on our Meta Keywords Generator page.<br/>Please update some settings to get more benefit Update settings
.
Version: 1.10
Author: Durgesh Chaudhary
Author URI: http://home.techphernalia.com/
*/
add_action('admin_menu', 'tp_mkg_add_page');
add_action('admin_init', 'tp_mkg_register');
add_action('wp_head','tp_act');
add_action('rightnow_end','tp_notify');
function tp_mkg_register(){
register_setting( 'tp_mkg_options', 'tp_mkg_options', 'tp_mkg_options_validate' );
add_settings_section('tp_mkg_main_section', 'Quick Settings', 'tp_mkg_section_main_render', 'techphernalia');
add_settings_field('tp_mkg_compulsary', 'Compulsary Keywords', 'tp_mkg_render_fields', 'techphernalia', 'tp_mkg_main_section');
}
function tp_mkg_add_page() {
add_options_page('Meta Keywords Generator', 'Meta Keywords Generator ', 'manage_options', 'techphernalia', 'tp_mkg_render_page');
}
function tp_mkg_render_page() {
echo '<style>#tp_promotion span {display: none;}#tp_promotion a{background: url(http://techphernalia.com/sprite_master.png) left top no-repeat;float: left;width: 32px;height: 32px;margin-right: 10px;}#tp_promotion a.twitter_link{ background-position: left -414px;}#tp_promotion a.facebook_link{background-position: -69px -414px;}</style>';
echo '<div class="wrap">
<center><h2>Meta Keywords Generator Settings</h2></center>
We are working continuously to provide you more SEO benefit and here comes the first in this series which allow you to provide some keywords which you want to be available on each and every web page served to your user. Currently we have only one setting we will have more soon.<br/><br/>Feel free to <b>request features</b> on our blog or on plugin page.
<form action="options.php" method="post">';
settings_fields('tp_mkg_options');
do_settings_sections('techphernalia');
echo '<input name="Submit" class="button-primary" type="submit" value="';
esc_attr_e('Save Changes');
echo'" />
</form></div>';
echo '<br/><br/><div id="tp_promotion"><a target="_blank" href="http://home.techphernalia.com/feed/" title="Subscribe to Our RSS feed" class="rss_link"><span>Subscribe to RSS feed</span></a>
<span>Follow us on Twitter</span><span>Visit us on Facebook</span>
</div>';
}
function tp_mkg_section_main_render() {
echo '<b>Compulsary Keywords</b> : Comma separated keywords which should appear on all the web page displayed.';
}
function tp_mkg_render_fields() {
$options = get_option('tp_mkg_options');
echo "<textarea id='tp_mkg_compulsary' name='tp_mkg_options[tp_mkg_compulsary]' cols='80' rows='10' maxlength='500' style='max-width:660px;max-height:164px;' >{$options['tp_mkg_compulsary']}</textarea>";
}
function tp_mkg_options_validate($input) {
$temp = trim($input['tp_mkg_compulsary']);
$temp = str_replace(";","",$temp);
$newinput['tp_mkg_compulsary'] = trim(str_replace("\"","",$temp));
return $newinput;
}
function tp_notify () {
echo '<p>SEO provided by <strong>Meta Keywords Generator</strong> from techphernalia.com</p>';
}
function tp_parse ($str) {
$str = str_replace("\"","'",$str);
$done = str_replace(", "," ",$str);
$done = str_replace(" ",", ",$done);
if (strpos($str," ")) return $str.", ".$done;
else return $str;
}
function tp_act () {
$name = get_option("blogname");
$desc = get_option("blogdescription");
if (is_tag()) $title = single_tag_title('',false);
if (is_category()) $title = single_cat_title('',false);
if (is_single() || is_page()) {
$add = "";
$postid = get_query_var("p");
$post = get_post($postid);
$title = single_post_title('',false);
$catlist = get_the_category($post->ID);
if (is_array($catlist)) { foreach ($catlist as $catlist) { $add .= ", ".$catlist->name; }}
$taglist = get_the_tags($post->ID);
if (is_array($taglist)) { foreach ($taglist as $taglist) { $add .= ", ".$taglist->name; }}
$description = substr(strip_tags($post->post_content),0,400);
}
$tp_mkg_options=get_option("tp_mkg_options");
echo '<!-- SEO by Meta Keywords Generator : techphernalia.com v1.10 start-->
';
if (!is_home()) {
echo '<meta name="keywords" content="'.tp_parse($title).', '.tp_parse($name).$add.", ".$tp_mkg_options["tp_mkg_compulsary"].'" />
<meta name="description" content="'.str_replace("\"","'",strip_shortcodes( $description )).'" />
';
} else {
echo '<meta name="keywords" content="'.tp_parse($desc).', '.$name.", ".$tp_mkg_options["tp_mkg_compulsary"].'" />
<meta name="description" content="'.str_replace("\"","'",strip_shortcodes( $desc )).'" />
';
}
echo '<!-- SEO by Meta Keywords Generator : techphernalia.com v1.10 end-->
';
}
?>
by default it is showing first 400 characters as description, i want to show Post title at the end and start of description,
any help will be highly appreciated.
Thanks
I am the author of this plugin, you could have asked this on official plugin url mentioned above.
We are generating description at this statement
$description = substr(strip_tags($post->post_content),0,400);
if you want to have site_title at beginning and at end, simply append $title at beginning and end.
$description = $title . substr(strip_tags($post->post_content),0,400) . $title;
but it may exceed 400 characters so you need to manage accordingly.
If you want to remove 400 chars limit remove substr part as
$description = $title . strip_tags($post->post_content) . $title;
PHP:
function get_t_wrinkle_rel(){
global $mysqli;
$q = $mysqli->query("SELECT * FROM t_wrinkle_rel ORDER BY t_wrinkle_name ASC");
while ($r = $q->fetch_array()) :
echo '<p><input type="checkbox"' . $r['t_wrinkle_name'] . '</p>';
endwhile;
}
RESULT:
<input type="checkbox" value="Crows feet">Crows feet
<input type="checkbox" value="Frown lines" >Frown lines
<input type="checkbox" value="Lip augmentation">Lip augmentation
<input type="checkbox" value="Lip lines">Lip lines
<input type="checkbox" value="Marionette lines">Marionette lines
i want the result:
**LEFT** **RIGHT**
<input type="checkbox">Crows feet |<input type="checkbox" >Lip lines
<input type="checkbox">Frown lines | <input type="checkbox">Marionette lines
<input type="checkbox"">Lip augmentation
Could you not alternate a class on each second input that suggests clearing a float or something similar if you are not floating the inputs? Something along the lines of:
function get_t_wrinkle_rel(){
global $mysqli;
$flag = 1;
$q = $mysqli->query("SELECT * FROM t_wrinkle_rel ORDER BY t_wrinkle_name ASC");
while ($r = $q->fetch_array()) :
if ($flag = 1) {
$orientate=left;$flag=0;
} else {
$orientate=right;$flag=1;
}
echo '<p><input class="' . $orientate . '"type="checkbox"' . $r['t_wrinkle_name'] . '</p>';
endwhile;
}
while ($left = $q->fetch_array()) {
echo '<p>';
echo '<input...>' . $left['...'];
if ($right = $q->fetch_array()) {
echo '| <input...>' . $right['...'];
}
echo '</p>';
}
This way should fill the left column in order then the right column, keeping the order you want to achieve. I don't have access to your database so I can't test this, but it should do the job.
function get_t_wrinkle_rel(){
global $mysqli;
$q = $mysqli->query("SELECT * FROM t_wrinkle_rel ORDER BY t_wrinkle_name ASC");
$mid = floor($q->num_rows/2); // Get halfway point
$count = 0;
$array = array();
while($r = $q->fetch_array()){
$string = '<input type="checkbox" value="'.$r['t_wrinkle_name'].'" />'.$r['t_wrinkle_name'];
if($count <= $mid){
// Left column
$array[$count] = $string;
} else {
// Right column
$array[$count-$mid] .= '|'.$string;
}
$count++;
}
// Make single string
echo implode('', $array);
}
However I would recommend using the idea biscuitstack suggested, using CSS to position it the way you want, rather than doing it programatically. It's always better to try to keep presentation separate from the logic wherever possible.
You could use flag that increments everytime and
<input type="checkbox"' . $r['t_wrinkle_name'] .
if flag % 2 == 0 then echo '<br />'
Or something like that.