donkeykong/sample php display order (sorting) for an array ( PHP)
/*
This is a very basic example of how to change the sort order of an array.
This information would normally be sent back to a database table.
*/
$arr[27]['id'] = 27;
$arr[27]['order'] = 1;
$arr[27]['name'] = 'about';
$arr[38]['id'] = 38;
$arr[38]['order'] = 2;
$arr[38]['name'] = 'contact';
$arr[52]['id'] = 52;
$arr[52]['order'] = 3;
$arr[52]['name'] = 'FAQ';
$arr[44]['id'] = 44;
$arr[44]['order'] = 4;
$arr[44]['name'] = 'Services';
$arr[45]['id'] = 45;
$arr[45]['order'] = 5;
$arr[45]['name'] = 'Sitemap';
echo 'original '.'<br />';
foreach($arr as $item)
{
echo 'Order: '.$item['order'].' '.$item['name'].'<br />';
}
$id = 44;
$int_new_order = 1;
$int_current_order = 4;
if( $int_new_order > $arr[$id]['order'] )
{
//echo 'move higher in number';
foreach($arr as $k=>$v)
{
if( $v['order'] > $int_current_order AND $v['order'] <= $int_new_order)
{
$arr[$k]['order'] = $v['order']-1;
}
}
}
else
{
//echo 'move lower in number';
foreach($arr as $k=>$v)
{
if( $v['order'] < $int_current_order AND $v['order'] >= $int_new_order)
{
$arr[$k]['order'] = $v['order']+1;
}
}
}
$arr[$id]['order'] = $int_new_order;
echo '<br />';
echo 'final '.'<br />';
foreach($arr as $item)
{
echo 'Order: '.$item['order'].' '.$item['name'].'<br />';
}
kevincam/Base display function to use Joomla! cache ( PHP)
/**
* Method to display a view.
*
* @param boolean If true, the view output will be cached
* @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return JController This object to support chaining.
* @since 1.5
*/
public function display($cachable = false, $urlparams = false)
{
$cachable = true;
// Get the document object.
$document = JFactory::getDocument();
$safeurlparams = array('catid'=>'INT', 'id'=>'INT', 'cid'=>'ARRAY', 'year'=>'INT', 'month'=>'INT', 'limit'=>'INT', 'limitstart'=>'INT', 'showall'=>'INT', 'return'=>'BASE64', 'filter'=>'STRING', 'filter_order'=>'CMD', 'filter_order_Dir'=>'CMD', 'filter-search'=>'STRING', 'print'=>'BOOLEAN', 'lang'=>'CMD');
parent::display($cachable, $safeurlparams);
return $this;
}
This is a base function to use with Joomla! to display the view using the Joomla cache system.
Mat_/Display wordpress posts with custom date meta value, ordered by this date, ( PHP)
$myrows = $wpdb->get_results("
SELECT wposts.post_title, wposts.ID , wpostmeta.meta_key, wpostmeta.meta_value
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wposts.post_type = 'concerts'
AND wpostmeta.meta_key = 'DateConcert'
AND CAST(wpostmeta.meta_value AS DATE) > '".date("Y-m-d H:i:s")."'
AND CAST(wpostmeta.meta_value AS DATE) < '".date("Y-m-d H:i:s", $date2)."'
AND wposts.post_status = 'publish'
ORDER BY CAST(wpostmeta.meta_value AS DATE) ASC
");
if ($myrows) :
foreach ($myrows as $post) :
setup_postdata($post);
?>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark"
title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php
endforeach;
else :
?>
<h2> Not Found</h2>
<?php endif; ?>
First you have to add a custom value with a correct date format.
The lines:
AND CAST(wpostmeta.meta_value AS DATE) > '".date("Y-m-d H:i:s")."'
AND CAST(wpostmeta.meta_value AS DATE) < '".date("Y-m-d H:i:s", $date2)."'
are only used to select dates between the current day and 2 months later
dottDesign/Wordpress Page Order ( Other)
<?php
/* Version 2.8b - http://www.geekyweekly.com/mypageorder */
function mypageorder_menu()
{ if (function_exists('add_submenu_page')) {
add_submenu_page(mypageorder_getTarget(), 'Page Order', __('Page Order', 'mypageorder'), 5,"mypageorder",'mypageorder');
}
}
function mypageorder_js_libs() {
if ( $_GET['page'] == "mypageorder" ) {
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-sortable');
}
}
//Switch page target depending on version
function mypageorder_getTarget() {
global $wp_version;
if (version_compare($wp_version, '2.6.5', '>'))
return "page-new.php";
else
return "edit.php";
}
add_action('admin_menu', 'mypageorder_menu');
add_action('admin_menu', 'mypageorder_js_libs');
function mypageorder() {
global $wpdb;
$mode = "";
$mode = $_GET['mode'];
$parentID = 0;
if (isset($_GET['parentID']))
$parentID = $_GET['parentID'];
$success = "";
if($mode == "act_OrderPages") {
$idString = $_GET['idString'];
$IDs = explode(",", $idString);
$result = count($IDs);
for($i = 0; $i < $result; $i++)
{
$wpdb->query("UPDATE $wpdb->posts SET menu_order = '$i' WHERE id ='$IDs[$i]'");
}
$success = '<div id="message" class="updated fade"><p>'. __('Page order updated successfully.', 'mypageorder').'</p></div>';
}
$subPageStr = "";
$results=$wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = $parentID and post_type = 'page' ORDER BY menu_order ASC");
foreach($results as $row)
{
$postCount=$wpdb->get_row("SELECT count(*) as postsCount FROM $wpdb->posts WHERE post_parent = $row->ID and post_type = 'page' ", ARRAY_N);
if($postCount[0] > 0)
$subPageStr = $subPageStr."<option value='$row->ID'>$row->post_title</option>";
}
?>
<div class='wrap'>
<h2><?php _e('Page Order', 'mypageorder') ?></h2>
<?php echo $success; ?>
<p><?php _e('Choose a page from the drop down to order its subpages or order the pages on this level by dragging and dropping them into the desired order.', 'mypageorder') ?></p>
<?php
if($parentID != 0)
{
$parentsParent = $wpdb->get_row("SELECT post_parent FROM $wpdb->posts WHERE ID = $parentID ", ARRAY_N);
echo "<a href='". mypageorder_getTarget() . "?page=mypageorder&parentID=$parentsParent[0]'>" . __('Return to parent page', 'mypageorder') . "</a>";
}
if($subPageStr != "") { ?>
<h3><?php _e('Order Subpages', 'mypageorder') ?></h3>
<select id="pages" name="pages"><?php
echo $subPageStr;
?>
</select>
&nbsp;<input type="button" name="edit" Value="<?php _e('Order Subpages', 'mypageorder') ?>" onClick="javascript:goEdit();">
<?php } ?>
<h3><?php _e('Order Pages', 'mypageorder') ?></h3>
<ul id="order" style="width: 500px; margin:10px 10px 10px 0px; padding:10px; border:1px solid #B2B2B2; list-style:none;"><?php
foreach($results as $row)
{
echo "<li id='$row->ID' class='lineitem'>$row->post_title</li>";
}?>
</ul>
<input type="button" id="orderButton" Value="<?php _e('Click to Order Pages', 'mypageorder') ?>" onclick="javascript:orderPages();">&nbsp;&nbsp;<strong id="updateText"></strong>
</div>
<style>
li.lineitem {
margin: 3px 0px;
padding: 2px 5px 2px 5px;
background-color: #F1F1F1;
border:1px solid #B2B2B2;
cursor: move;
width: 490px;
}
</style>
<script language="JavaScript">
jQuery(document).ready(function(){
jQuery("#order").sortable({
placeholder: "ui-selected",
revert: false,
tolerance: "pointer"
});
});
function orderPages() {
jQuery("#orderButton").css("display", "none");
jQuery("#updateText").html("<?php _e('Updating Page Order...', 'mypageorder') ?>");
idList = jQuery("#order").sortable("toArray");
location.href = '<?php echo mypageorder_getTarget(); ?>?page=mypageorder&mode=act_OrderPages&parentID=<?php echo $parentID; ?>&idString='+idList;
}
function goEdit () {
if(jQuery("#pages").val() != "")
location.href="<?php echo mypageorder_getTarget(); ?>?page=mypageorder&mode=dsp_OrderPages&parentID="+jQuery("#pages").val();
}
</script>
<?php
}
?>
Add to functions.php/* Page Order */include('library/functions/page-order.php');
javifr/Order posts- order by meta ( PHP)
<?php // grab posts by post count ordered in descending order (most votes first) $query = 'meta_key=vote_count&orderby=meta_value&order=DESC'; $queryObject = new WP_Query($query); // The Loop... ?>
Mat_/Display wordpress posts with custom date meta value, ordered by this date, with a defined taxonomy ( PHP)
$myrows = $wpdb->get_results("
SELECT wposts.post_title, wposts.ID
FROM $wpdb->posts wposts
LEFT JOIN $wpdb->term_relationships ON(wposts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
LEFT JOIN $wpdb->postmeta ON(wposts.ID = $wpdb->postmeta.post_id)
WHERE wposts.post_status = 'publish'
AND wposts.post_type = 'concerts'
AND $wpdb->postmeta.meta_key = 'DateConcert'
AND CAST($wpdb->postmeta.meta_value AS DATE) > '".date("Y-m-d H:i:s")."'
AND CAST($wpdb->postmeta.meta_value AS DATE) < '".date("Y-m-d H:i:s", $date2)."'
AND $wpdb->term_taxonomy.taxonomy = 'Genres'
AND $wpdb->terms.slug = 'Jazz'
ORDER BY CAST($wpdb->postmeta.meta_value AS DATE) ASC
");
erraja_07/PHP - Display Updated time ( PHP)
function time_ago( $datefrom )
{
$dateto = date('Y-m-d H:i:s');
// echo $dateto."-";
// echo $datefrom;
if($datefrom<=0) { return "A long time ago"; }
if($dateto==-1) { $dateto = time(); }
$difference = $dateto - $datefrom;
// Seconds
if($difference < 60)
{
// $time_ago = $difference . ' second' . ( $difference > 1 ? 's' : '' ).' ago';
$time_ago ='Just now';
}
// Minutes
else if( $difference < 60*60 )
{
$ago_seconds = $difference % 60;
$ago_seconds = ( ( $ago_seconds AND $ago_seconds > 1 ) ? ' and '.$ago_seconds.' seconds' : ( $ago_seconds == 1 ? ' and '.$ago_seconds.' second' : '' ) );
$ago_minutes = floor( $difference / 60 );
$ago_minutes = $ago_minutes . ' minute' . ( $ago_minutes > 1 ? 's' : '' ).' ago';
$time_ago = $ago_minutes;
}
// Hours
else if ( $difference < 60*60*24 )
{
$ago_minutes = round( $difference / 60 ) % 60 ;
$ago_minutes = ( ( $ago_minutes AND $ago_minutes > 1 ) ? ' and ' . $ago_minutes . ' minutes' : ( $ago_minutes == 1 ? ' and ' . $ago_minutes .' minute' : '' ));
$ago_hours = floor( $difference / ( 60 * 60 ) );
$ago_hours = $ago_hours . ' hour'. ( $ago_hours > 1 ? 's' : '' );
$time_ago = $ago_hours.$ago_minutes.' ago';
}
// Days
else if ( $difference < 60*60*24*7 )
{
$ago_hours = round( $difference / 3600 ) % 24 ;
$ago_hours = ( ( $ago_hours AND $ago_hours > 1 ) ? ' and ' . $ago_hours . ' hours' : ( $ago_hours == 1 ? ' and ' . $ago_hours . ' hour' : '' ));
$ago_days = floor( $difference / ( 3600 * 24 ) );
$ago_days = $ago_days . ' day' . ($ago_days > 1 ? 's' : '' );
$time_ago = $ago_days.$ago_hours.' ago';
}
// Weeks
else if ( $difference < 60*60*24*30 )
{
$ago_days = round( $difference / ( 3600 * 24 ) ) % 7;
$ago_days = ( ( $ago_days AND $ago_days > 1 ) ? ' and '.$ago_days.' days' : ( $ago_days == 1 ? ' and '.$ago_days.' day' : '' ));
$ago_weeks = floor( $difference / ( 3600 * 24 * 7) );
$ago_weeks = $ago_weeks . ' week'. ($ago_weeks > 1 ? 's' : '' );
$time_ago = $ago_weeks.$ago_days.' ago';
}
// Months
else if ( $difference < 60*60*24*365 )
{
$days_diff = round( $difference / ( 60 * 60 * 24 ) );
$ago_days = $days_diff % 30 ;
$ago_weeks = round( $ago_days / 7 ) ;
$ago_weeks = ( ( $ago_weeks AND $ago_weeks > 1 ) ? ' and '.$ago_weeks.' weeks' : ( $ago_weeks == 1 ? ' and '.$ago_weeks.' week' : '' ) );
$ago_months = floor( $days_diff / 30 );
$ago_months = $ago_months .' month'. ( $ago_months > 1 ? 's' : '' );
$time_ago = $ago_months.$ago_weeks.' ago';
}
// Years
else if ( $difference >= 60*60*24*365 )
{
$ago_months = round( $difference / ( 60 * 60 * 24 * 30.5 ) ) % 12;
$ago_months = ( ( $ago_months AND $ago_months > 1 ) ? ' and ' . $ago_months . ' months' : ( $ago_months == 1 ? ' and '.$ago_months.' month' : '' ) );
$ago_years = floor( $difference / ( 60 * 60 * 24 * 365 ) );#30 * 12
$ago_years = $ago_years . ' year'. ($ago_years > 1 ? 's' : '' ) ;
$time_ago = $ago_years.$ago_months.' ago';
}
return $time_ago;
}
xida/Order Array ( PHP)
function sortiere ( $a, $b )
{
if ($a['timestamp'] == $b['timestamp'])
{
return 0;
}
if ($a['timestamp'] > $b['timestamp'] ) {
return -1;
} else {
return 1;
}
}
uasort ( $twitter, 'sortiere' );
ablears/Wordpress custom sitemap shortcode following custom menu order ( PHP)
//Our custom sitemap which reads the menu order using extended menu walker class
//Shortcode
function wdp_shortcode_sitemap($atts){ //[sitemap]
extract(shortcode_atts(array(
), $atts));
//call the function
$shortcodecontent = wdp_sitemap();
return $shortcodecontent;
}
add_shortcode('sitemap', 'wdp_shortcode_sitemap');
//call the menu and use our custom walker
function wdp_sitemap(){
return wp_nav_menu(array('theme_location' => 'primary', 'walker' => new wdp_sitemap_walker(), 'fallback_cb' => '', 'echo'=>false));
}
//extended navigation class for sitemap rendering
class wdp_sitemap_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$id=strtolower(str_replace(" ","-",$item->title));
$id=str_replace(array('&','&amp;'),"",$id);
$id=str_replace('--',"-",$id);
$output .= $indent . '<li id="sitemap-'. $id . '"' . $value .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
//$item_output .= $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
// $item_output .= $args->link_after;
$item_output .= '</a>';
//$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
Use a shortcode [sitemap] to render a sitemap ordered by custom menu order (Wordpress 3+).
lromak/Customizing Post Sort Order Using the Category Posts Widget ( PHP)
// Get array of post info.
$cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"] . '&orderby=date&order=asc');
The Category Posts Widget is very good for showing a certain # of posts in a particular category using a widget that displays on every page. However, if you only want to show the posts for the current category in the sidebar, then add this code to your sidebar.php file:
<?php
$sidebar_related_query = new WP_Query('cat=' . $sidebar_cat_id . '&showposts=5&offset=0&orderby=post_date&order=desc');
while ($sidebar_related_query->have_posts()) : $sidebar_related_query->the_post();
$do_not_duplicate = $post->ID;
?>
<div id=”post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
</div>
<?php endwhile; ?>
Edit widget or display current category in sidebar.php
jmiller/Sort a multi-dimensional field ( PHP)
function orderBy($data, $field) {
$code = "return strnatcmp(\$a['$field'], \$b['$field']);";
usort($data, create_function('$a,$b', $code));
return $data;
}
Orders a multi-dimensional field (such as sorting multiple $orders by field 'id')
BoNzO/Ordinamento per data inverso dei post su Wordpress ( PHP)
<?php query_posts($query_string."&orderby=date&order=ASC"); ?> <?php while (have_posts()) : the_post(); ?>
Abe/Posts by month ( PHP)
function monthNewsList() {
$query = "SELECT COUNT(id) total, MONTHNAME(date) month, YEAR(date) year ";
$query .= "FROM news ";
$query .= "GROUP BY MONTH(date), YEAR(date) ";
$query .= "ORDER BY date ";
$result = mysql_query($query);
$count = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
echo $row["month"].' '.$row["year"].' ('.$row["total"].")<br />\n";
}
mysql_free_result($result);
}
Ijaas/myCategoryOrder Custom Taxonomy mod ( PHP)
<?php
/*
Plugin Name: My Category Order
Plugin URI: http://www.geekyweekly.com/mycategoryorder
Description: My Category Order allows you to set the order in which categories will appear in the sidebar. Uses a drag and drop interface for ordering. Adds a widget with additional options for easy installation on widgetized themes.
Version: 3.0.1
Author: Andrew Charlton & modified by Ijaas (http://www.dex-labs.com)
Author URI: http://www.geekyweekly.com
Author Email: froman118@gmail.com
*/
function mycategoryorder_init() {
function mycategoryorder_menu()
{
add_posts_page(__('My Category Order', 'mycategoryorder'), __('My Category Order', 'mycategoryorder'), 'manage_categories', 'mycategoryorder', 'mycategoryorder');
}
function mycategoryorder_js_libs() {
if ( isset($_GET['page']) && $_GET['page'] == "mycategoryorder" )
{
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-sortable');
}
}
//Switch page target depending on version
function mycategoryorder_getTarget() {
return "edit.php";
}
function mycategoryorder_set_plugin_meta($links, $file) {
$plugin = plugin_basename(__FILE__);
// create link
if ($file == $plugin) {
return array_merge( $links, array(
'<a href="' . mycategoryorder_getTarget() . '">' . __('Order Categories', 'mycategoryorder') . '</a>',
'<a href="http://wordpress.org/tags/my-category-order?forum_id=10#postform">' . __('Support Forum') . '</a>',
'<a href="http://geekyweekly.com/gifts-and-donations">' . __('Donate') . '</a>'
));
}
return $links;
}
add_filter('plugin_row_meta', 'mycategoryorder_set_plugin_meta', 10, 2 );
add_action('admin_menu', 'mycategoryorder_menu');
add_action('admin_print_scripts', 'mycategoryorder_js_libs');
//Define selected taxonomy
$tax = ($_GET['mytax'])? $_GET['mytax'] : 'category';
define('myTAXONOMY', $tax, true);
function mycategoryorder()
{
global $wpdb;
$parentID = 0;
$wpdb->show_errors();
$query1 = $wpdb->query("SHOW COLUMNS FROM $wpdb->terms LIKE 'term_order'");
if ($query1 == 0) {
$wpdb->query("ALTER TABLE $wpdb->terms ADD `term_order` INT( 4 ) NULL DEFAULT '0'");
}
if (isset($_POST['btnSubCats'])) {
$parentID = $_POST['cats'];
}
elseif (isset($_POST['hdnParentID'])) {
$parentID = $_POST['hdnParentID'];
}
if (isset($_POST['btnReturnParent'])) {
$parentsParent = $wpdb->get_row("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = " . $_POST['hdnParentID'], ARRAY_N);
$parentID = $parentsParent[0];
}
if(isset($_GET['hideNote']))
update_option('mycategoryorder_hideNote', '1');
$success = "";
if (isset($_POST['btnOrderCats'])) {
$success = mycategoryorder_updateOrder();
}
$subCatStr = mycategoryorder_getSubCats($parentID);
?>
<div class='wrap'>
<?php //Start of Custom taxonomy ?>
<form name="frmMyCatOrderTax" method="get" action="">
<input type="hidden" name="page" value="<?php echo $_GET['page']; ?>" />
<h2><?php _e('My Category Order','mycategoryorder'); ?></h2>
<?php
if (get_option("mycategoryorder_hideNote") != "1")
{ ?>
<div class="updated">
<strong><p><?php _e('If you like my plugin please consider donating. Every little bit helps me provide support and continue development.','mycategoryorder'); ?> <a href="http://geekyweekly.com/gifts-and-donations"><?php _e('Donate', 'mycategoryorder'); ?></a>&nbsp;&nbsp;<small><a href="<?php echo mycategoryorder_getTarget(); ?>&hideNote=true"><?php _e('No thanks, hide this', 'mycategoryorder'); ?></a></small></p></strong>
</div>
<?php
} ?>
<p><?php _e('Choose a taxonomy from the drop down to order its terms','mycategoryorder'); ?></p>
<?php
// Custom Taxonomy dropdown
$taxes = get_taxonomies(); $taxlist = array();
echo "<select name='mytax'>";
foreach($taxes as $tax):
if(is_taxonomy_hierarchical($tax)):
$tax = get_taxonomy($tax);
$s = (myTAXONOMY == $tax->name)? "selected='selected'" : '';
echo "<option ".$s." value='".$tax->name."'>".$tax->label."</option>";
endif;
endforeach;
echo "</select>";
?>
<input type="submit" class="button" value="<?php _e('Change Taxonomy', 'mycategoryorder') ?>" />
</form>
<?php //End of Custom taxonomy ?>
<form name="frmMyCatOrder" method="post" action="">
<?php
echo $success;
?>
<p><?php _e('Choose a category from the drop down to order subcategories in that category or order the categories on this level by dragging and dropping them into the desired order.','mycategoryorder'); ?></p>
<?php
if($subCatStr != "")
{
?>
<h3><?php _e('Order Subcategories','mycategoryorder'); ?></h3>
<select id="cats" name="cats">
<?php echo $subCatStr; ?>
</select>
&nbsp;<input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="<?php _e('Order Subcategories','mycategoryorder'); ?>" />
<?php } ?>
<h3><?php _e('Order Categories','mycategoryorder'); ?></h3>
<ul id="myCategoryOrderList">
<?php
$results= mycategoryorder_catQuery($parentID);
foreach($results as $row)
echo "<li id='id_$row->term_id' class='lineitem'>".__($row->name)."</li>";
?>
</ul>
<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="<?php _e('Click to Order Categories', 'mycategoryorder') ?>" onclick="javascript:orderCats(); return true;" />
<?php echo mycategoryorder_getParentLink($parentID); ?>
&nbsp;&nbsp;<strong id="updateText"></strong>
<br /><br />
<p>
<a href="http://geekyweekly.com/mycategoryorder"><?php _e('Plugin Homepage', 'mycategoryorder') ?></a>&nbsp;|&nbsp;<a href="http://geekyweekly.com/gifts-and-donations"><?php _e('Donate', 'mycategoryorder') ?></a>&nbsp;|&nbsp;<a href="http://wordpress.org/tags/my-category-order?forum_id=10"><?php _e('Support Forum', 'mycategoryorder') ?></a>
</p>
<input type="hidden" id="hdnMyCategoryOrder" name="hdnMyCategoryOrder" />
<input type="hidden" id="hdnParentID" name="hdnParentID" value="<?php echo $parentID; ?>" />
</form>
</div>
<style type="text/css">
#myCategoryOrderList {
width: 90%;
border:1px solid #B2B2B2;
margin:10px 10px 10px 0px;
padding:5px 10px 5px 10px;
list-style:none;
background-color:#fff;
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
li.lineitem {
border:1px solid #B2B2B2;
-moz-border-radius:3px;
-webkit-border-radius:3px;
background-color:#F1F1F1;
color:#000;
cursor:move;
font-size:13px;
margin-top:5px;
margin-bottom:5px;
padding: 2px 5px 2px 5px;
height:1.5em;
line-height:1.5em;
}
.sortable-placeholder{
border:1px dashed #B2B2B2;
margin-top:5px;
margin-bottom:5px;
padding: 2px 5px 2px 5px;
height:1.5em;
line-height:1.5em;
}
</style>
<script type="text/javascript">
// <![CDATA[
function mycategoryrderaddloadevent(){
jQuery("#myCategoryOrderList").sortable({
placeholder: "sortable-placeholder",
revert: false,
tolerance: "pointer"
});
};
addLoadEvent(mycategoryrderaddloadevent);
function orderCats() {
jQuery("#updateText").html("<?php _e('Updating Category Order...', 'mycategoryorder') ?>");
jQuery("#hdnMyCategoryOrder").val(jQuery("#myCategoryOrderList").sortable("toArray"));
}
// ]]>
</script>
<?php
}
}
function mycategoryorder_getSubCats($parentID)
{
global $wpdb;
$subCatStr = "";
$results=$wpdb->get_results("SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = $parentID AND tt.taxonomy = '".myTAXONOMY."' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.term_order ASC");
foreach($results as $row)
{
$subCatStr = $subCatStr."<option value='$row->term_id'>$row->name</option>";
}
return $subCatStr;
}
function mycategoryorder_updateOrder()
{
if (isset($_POST['hdnMyCategoryOrder']) && $_POST['hdnMyCategoryOrder'] != "") {
global $wpdb;
$hdnMyCategoryOrder = $_POST['hdnMyCategoryOrder'];
$IDs = explode(",", $hdnMyCategoryOrder);
$result = count($IDs);
for($i = 0; $i < $result; $i++)
{
$str = str_replace("id_", "", $IDs[$i]);
$wpdb->query("UPDATE $wpdb->terms SET term_order = '$i' WHERE term_id ='$str'");
}
return '<div id="message" class="updated fade"><p>'. __('Categories updated successfully.', 'mycategoryorder').'</p></div>';
}
else
return '<div id="message" class="updated fade"><p>'. __('An error occured, order has not been saved.', 'mycategoryorder').'</p></div>';
}
function mycategoryorder_catQuery($parentID)
{
global $wpdb;
return $wpdb->get_results("SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = '".myTAXONOMY."' and parent = $parentID ORDER BY term_order ASC");
}
function mycategoryorder_getParentLink($parentID)
{
if($parentID != 0)
return "&nbsp;&nbsp;<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . __('Return to parent category', 'mycategoryorder') ."' />";
else
return "";
}
function mycategoryorder_applyorderfilter($orderby, $args)
{
if($args['orderby'] == 'order')
return 't.term_order';
else
return $orderby;
}
add_filter('get_terms_orderby', 'mycategoryorder_applyorderfilter', 10, 2);
add_action('plugins_loaded', 'mycategoryorder_init');
/* Load Translations */
add_action('init', 'mycategoryorder_loadtranslation');
function mycategoryorder_loadtranslation() {
load_plugin_textdomain('mycategoryorder', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
}
class mycategoryorder_Widget extends WP_Widget {
function mycategoryorder_Widget() {
$widget_ops = array('classname' => 'widget_mycategoryorder', 'description' => __( 'Enhanced Category widget provided by My Category Order') );
$this->WP_Widget('mycategoryorder', __('My Category Order'), $widget_ops); }
function widget( $args, $instance ) {
extract( $args );
$title_li = apply_filters('widget_title', empty( $instance['title_li'] ) ? __( 'Categories' ) : $instance['title_li']);
$orderby = empty( $instance['orderby'] ) ? 'order' : $instance['orderby'];
$order = empty( $instance['order'] ) ? 'asc' : $instance['order'];
$show_dropdown = (bool) $instance['show_dropdown'];
$show_last_updated = (bool) $instance['show_last_updated'];
$show_count = (bool) $instance['show_count'];
$hide_empty = (bool) $instance['hide_empty'];
$use_desc_for_title = (bool) $instance['use_desc_for_title'];
$child_of = empty( $instance['child_of'] ) ? '' : $instance['child_of'];
$feed = empty( $instance['feed'] ) ? '' : $instance['feed'];
$feed_image = empty( $instance['feed_image'] ) ? '' : $instance['feed_image'];
$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
$exclude_tree = empty( $instance['exclude_tree'] ) ? '' : $instance['exclude_tree'];
$include = empty( $instance['include'] ) ? '' : $instance['include'];
$hierarchical = empty( $instance['hierarchical'] ) ? '1' : $instance['hierarchical'];
$number = empty( $instance['number'] ) ? '' : $instance['number'];
$depth = empty( $instance['depth'] ) ? '0' : $instance['depth'];
echo $before_widget;
if ( $title_li )
echo $before_title . $title_li . $after_title;
$cat_args = array('orderby' => $orderby, 'order' => $order, 'show_last_updated' => $show_last_updated, 'show_count' => $show_count,
'hide_empty' => $hide_empty, 'use_desc_for_title' => $use_desc_for_title, 'child_of' => $child_of, 'feed' => $feed,
'feed_image' => $feed_image, 'exclude' => $exclude, 'exclude_tree' => $exclude_tree, 'include' => $include,
'hierarchical' => $hierarchical, 'number' => $number, 'depth' => $depth, );
if ( $show_dropdown ) {
static $dropdown_count = 0;
$cat_id = 'dropdown_'.$args['widget_id'];
$cat_args['id'] = $cat_args['name'] = $cat_id;
$cat_args['show_option_none'] = __('Select Category');
wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
?>
<script type='text/javascript'>
/* <![CDATA[ */
<?php if ( $dropdown_count == 0 ) { ?>
function onCatChange( dropdownID ) {
var dropdown = document.getElementById(dropdownID);
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
}
}
<?php } ?>
document.getElementById("<?php echo $cat_id; ?>").onchange = function(){onCatChange(this.id)};
/* ]]> */
</script>
<?php
$dropdown_count++;
} else {
?>
<ul>
<?php
$cat_args['title_li'] = '';
wp_list_categories(apply_filters('widget_categories_args', $cat_args));
?>
</ul>
<?php
}
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
if ( in_array( $new_instance['orderby'], array( 'order', 'name', 'count', 'ID', 'slug', 'term_group' ) ) ) {
$instance['orderby'] = $new_instance['orderby'];
} else {
$instance['orderby'] = 'order';
}
if ( in_array( $new_instance['order'], array( 'asc', 'desc' ) ) ) {
$instance['order'] = $new_instance['order'];
} else {
$instance['order'] = 'asc';
}
$instance['title_li'] = strip_tags( $new_instance['title_li'] );
$instance['show_dropdown'] = strip_tags( $new_instance['show_dropdown'] );
$instance['show_last_updated'] = strip_tags( $new_instance['show_last_updated'] );
$instance['show_count'] = strip_tags( $new_instance['show_count'] );
$instance['hide_empty'] = strip_tags( $new_instance['hide_empty'] );
$instance['use_desc_for_title'] = strip_tags( $new_instance['use_desc_for_title'] );
$instance['child_of'] = strip_tags( $new_instance['child_of'] );
$instance['feed'] = strip_tags( $new_instance['feed'] );
$instance['feed_image'] = $new_instance['feed_image'];
$instance['exclude'] = strip_tags( $new_instance['exclude'] );
$instance['exclude_tree'] = strip_tags( $new_instance['exclude_tree'] );
$instance['include'] = strip_tags( $new_instance['include'] );
$instance['hierarchical'] = strip_tags( $new_instance['hierarchical'] );
$instance['number'] = $new_instance['number'];
$instance['depth'] = $new_instance['depth'];
return $instance;
}
function form( $instance ) {
//Defaults
$instance = wp_parse_args( (array) $instance, array( 'orderby' => 'order', 'order' => 'asc', 'title_li' => '', 'show_dropdown' => '', 'show_last_updated' => '', 'show_count' => '', 'hide_empty' => '1', 'use_desc_for_title' => '1', 'child_of' => '', 'feed' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'include' => '', 'hierarchical' => '1', 'number' => '', 'depth' => '' ) );
$orderby = esc_attr( $instance['orderby'] );
$order = esc_attr( $instance['order'] );
$title_li = esc_attr( $instance['title_li'] );
$show_dropdown = esc_attr( $instance['show_dropdown'] );
$show_last_updated = esc_attr( $instance['show_last_updated'] );
$show_count = esc_attr( $instance['show_count'] );
$hide_empty = esc_attr( $instance['hide_empty'] );
$use_desc_for_title = esc_attr( $instance['use_desc_for_title'] );
$hierarchical = esc_attr( $instance['hierarchical'] );
$child_of = esc_attr( $instance['child_of'] );
$feed = esc_attr( $instance['feed'] );
$feed_image = esc_attr( $instance['feed_image'] );
$exclude = esc_attr( $instance['exclude'] );
$exclude_tree = esc_attr( $instance['exclude_tree'] );
$include = esc_attr( $instance['include'] );
$number = esc_attr( $instance['number'] );
$depth = esc_attr( $instance['depth'] );
?>
<p>
<label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Order By:', 'mycategoryorder' ); ?></label>
<select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
<option value="order"<?php selected( $instance['orderby'], 'order' ); ?>><?php _e('My Order', 'mycategoryorder'); ?></option>
<option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e('Name', 'mycategoryorder'); ?></option>
<option value="count"<?php selected( $instance['orderby'], 'count' ); ?>><?php _e( 'Count', 'mycategoryorder' ); ?></option>
<option value="ID"<?php selected( $instance['orderby'], 'ID' ); ?>><?php _e( 'ID', 'mycategoryorder' ); ?></option>
<option value="slug"<?php selected( $instance['orderby'], 'slug' ); ?>><?php _e( 'Slug', 'mycategoryorder' ); ?></option>
<option value="term_group"<?php selected( $instance['orderby'], 'term_group' ); ?>><?php _e( 'Term Group', 'mycategoryorder' ); ?></option>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('order'); ?>"><?php _e( 'Order:', 'mycategoryorder' ); ?></label>
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('category_order'); ?>" class="widefat">
<option value="asc"<?php selected( $instance['order'], 'asc' ); ?>><?php _e('Ascending', 'mycategoryorder'); ?></option>
<option value="desc"<?php selected( $instance['order'], 'desc' ); ?>><?php _e('Descending', 'mycategoryorder'); ?></option>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('title_li'); ?>"><?php _e( 'Title:', 'mycategoryorder' ); ?></label> <input type="text" value="<?php echo $title_li; ?>" name="<?php echo $this->get_field_name('title_li'); ?>" id="<?php echo $this->get_field_id('title_li'); ?>" class="widefat" />
<br />
<small><?php _e( 'Default to Categories.', 'mycategoryorder' ); ?></small>
</p>
<p>
<label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e( 'Exclude:', 'mycategoryorder' ); ?></label> <input type="text" value="<?php echo $exclude; ?>" name="<?php echo $this->get_field_name('exclude'); ?>" id="<?php echo $this->get_field_id('exclude'); ?>" class="widefat" />
<br />
<small><?php _e( 'Category IDs, separated by commas.', 'mycategoryorder' ); ?></small>
</p>
<p>
<label for="<?php echo $this->get_field_id('exclude_tree'); ?>"><?php _e( 'Exclude Tree:', 'mycategoryorder' ); ?></label> <input type="text" value="<?php echo $exclude_tree; ?>" name="<?php echo $this->get_field_name('exclude_tree'); ?>" id="<?php echo $this->get_field_id('exclude_tree'); ?>" class="widefat" />
<br />
<small><?php _e( 'Category IDs, separated by commas.', 'mycategoryorder' ); ?></small>
</p>
<p>
<label for="<?php echo $this->get_field_id('include'); ?>"><?php _e( 'Include:', 'mycategoryorder' ); ?></label> <input type="text" value="<?php echo $include; ?>" name="<?php echo $this->get_field_name('include'); ?>" id="<?php echo $this->get_field_id('include'); ?>" class="widefat" />
<br />
<small><?php _e( 'Category IDs, separated by commas.', 'mycategoryorder' ); ?></small>
</p>
<p>
<label for="<?php echo $this->get_field_id('child_of'); ?>"><?php _e( 'Child Of:', 'mycategoryorder' ); ?></label> <input type="text" value="<?php echo $child_of; ?>" name="<?php echo $this->get_field_name('child_of'); ?>" id="<?php echo $this->get_field_id('child_of'); ?>" class="widefat" />
<br />
<small><?php _e( 'Only display children of this Category ID.', 'mycategoryorder' ); ?></small>
</p>
<p>
<label for="<?php echo $this->get_field_id('feed'); ?>"><?php _e( 'Feed Text:', 'mycategoryorder' ); ?></label> <input type="text" value="<?php echo $feed; ?>" name="<?php echo $this->get_field_name('feed'); ?>" id="<?php echo $this->get_field_id('feed'); ?>" class="widefat" />
<br />
<small><?php _e( 'Text for RSS Feed', 'mycategoryorder' ); ?></small>
</p>
<p>
<label for="<?php echo $this->get_field_id('feed_image'); ?>"><?php _e( 'Feed Image:', 'mycategoryorder' ); ?></label> <input type="text" value="<?php echo $feed_image; ?>" name="<?php echo $this->get_field_name('feed_image'); ?>" id="<?php echo $this->get_field_id('feed_image'); ?>" class="widefat" />
<br />
<small><?php _e( 'URL to RSS Image, copy url of this image', 'mycategoryorder' ); ?></small><img src="<?php bloginfo('url'); ?>/wp-includes/images/rss.png" alt="RSS" />
</p>
<p>
<label for="<?php echo $this->get_field_id('number'); ?>"><?php _e( 'Number to Display:', 'mycategoryorder' ); ?></label> <input type="text" value="<?php echo $number; ?>" name="<?php echo $this->get_field_name('number'); ?>" id="<?php echo $this->get_field_id('number'); ?>" class="widefat" />
<br />
<small><?php _e( 'Max number of categories to display', 'mycategoryorder' ); ?></small>
</p>
<p>
<label for="<?php echo $this->get_field_id('depth'); ?>"><?php _e( 'Depth:', 'mycategoryorder' ); ?></label> <input type="text" value="<?php echo $depth; ?>" name="<?php echo $this->get_field_name('depth'); ?>" id="<?php echo $this->get_field_id('depth'); ?>" class="widefat" />
<br />
<small><?php _e( '0 = All, -1 = Flat, 1 = Top Level Only, n = display n levels', 'mycategoryorder' ); ?></small>
</p>
<p>
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['show_dropdown'], true) ?> id="<?php echo $this->get_field_id('show_dropdown'); ?>" name="<?php echo $this->get_field_name('show_dropdown'); ?>" />
<label for="<?php echo $this->get_field_id('show_dropdown'); ?>"><?php _e('Show As Dropdown', 'mycategoryorder'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['show_last_updated'], true) ?> id="<?php echo $this->get_field_id('show_last_updated'); ?>" name="<?php echo $this->get_field_name('show_last_updated'); ?>" />
<label for="<?php echo $this->get_field_id('show_last_updated'); ?>"><?php _e('Show Last Updated', 'mycategoryorder'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['show_count'], true) ?> id="<?php echo $this->get_field_id('show_count'); ?>" name="<?php echo $this->get_field_name('show_count'); ?>" />
<label for="<?php echo $this->get_field_id('show_count'); ?>"><?php _e('Show Count', 'mycategoryorder'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['hide_empty'], true) ?> id="<?php echo $this->get_field_id('hide_empty'); ?>" name="<?php echo $this->get_field_name('hide_empty'); ?>" />
<label for="<?php echo $this->get_field_id('hide_empty'); ?>"><?php _e('Hide Empty', 'mycategoryorder'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['use_desc_for_title'], true) ?> id="<?php echo $this->get_field_id('use_desc_for_title'); ?>" name="<?php echo $this->get_field_name('use_desc_for_title'); ?>" />
<label for="<?php echo $this->get_field_id('use_desc_for_title'); ?>"><?php _e('Use Desc as Title', 'mycategoryorder'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['hierarchical'], true) ?> id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>" />
<label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e('Show Hierarchical', 'mycategoryorder'); ?></label><br />
</p>
<?php
}
}
function mycategoryorder_widgets_init() {
register_widget('mycategoryorder_Widget');
}
add_action('widgets_init', 'mycategoryorder_widgets_init');
?>
replaced taxonomy = 'category' with taxonomy = '".myTAXONOMY."' add lines 51, 52, 93 - 123
aleprieto/Block that displays terms in a vocabulary as a list of links ( PHP)
<?php
/**
* Lists terms for a specific vocabulary without descriptions.
* Each term links to the corresponding /taxonomy/term/tid listing page.
*/
$vid = 1;
$items = array();
$terms = taxonomy_get_tree($vid, 0, -1, 1);
foreach($terms as $term){
$items[]= l($term->name, "taxonomy/term/$term->tid");
}
if(count($items)) {
return theme('item_list',$items);
}
?>
This is a simple little block that displays a list of terms in a vocabulary as a list of links to /taxonomy/term/tid pages. Items are listed in the order set for the vocabulary. You could probably use the php sort() function to change that if desired.
Be sure to change the $vid to reflect the vocabulary id of the vocabulary you wish to list. Also, you can change the "taxonomy/term/$term->tid" to any path you wish.