Frågan 3 mars 2009 15:45 #1 Använder Wordpress och ett plugins "Most Read in XX Days". Problemet är att listan ser konstig ut, blir två kolumner och där det inte får plats på en rad skriver det över texten på raden under.
Vill helt enkelt det ska se ut såhär:
aaaaaaaaaaaaaaa
bbbbbbbbbbbbbb
bbbbbbbbbbbbbb
ccccccccccc
gggggggg
hhhhhhhhhhhhhh
hhhhhhhhh
Tror problemet ligger i att tillägget har en lista och mitt template har en. Vill ramen ska ha samma design som Kategorier och Arkiv.
Problemet är under MEST LÄSTA NYHETERNA på http://undvikreklam.com/
Kod för min sidebar:
<div class="rsidebar">
<ul>
<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar() ) : else : ?>
<?php wp_list_categories('show_count=0&title_li=<h2>Kategorier</h2>'); ?>
<li><h2>Arkiv</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
</li>
<!-- <?php wp_list_bookmarks(); ?> -->
<li><h2>Mest lästa nyheterna</h2>
<ul>
<?php ST4_mostread(30,5,'yes'); ?>
<?php endif; ?>
</ul>
</li>
</div>
Kod för tillägget (postar hela):
<?php
$currentLocale = get_locale();
if(!empty($currentLocale)) {
$moFile = dirname(__FILE__) . "/most-read-plugin/most_read-" . $currentLocale . ".mo";
if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('most_read', $moFile);
}
function ST4_most_read_init_widgets(){
if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
return;
function ST4_most_read_widget($args) {
extract($args);
$options = get_option('most_read_widget_options');
$title = empty($options['title']) ? 'Most Read Posts' : $options['title'];
$quanti = empty($options['quanti']) ? '30' : $options['quanti'];
$limit = empty($options['limit']) ? '5' : $options['limit'];
$widget_show_hits = empty($options['widget_show_hits']) ? 'no' : $options['widget_show_hits'];
echo $before_widget;
echo $before_title . $title . $after_title;
ST4_mostread($quanti,$limit,$widget_show_hits);
echo $after_widget;
}
function ST4_most_read_widget_control() {
$options = get_option('most_read_widget_options');
if ( $_POST['mywidget-submit'] ) {
$newoptions['title'] = strip_tags(stripslashes($_POST['mywidget-title']));
$newoptions['quanti'] = strip_tags(stripslashes($_POST['mywidget-text']));
$newoptions['limit'] = strip_tags(stripslashes($_POST['mywidget-limit']));
$newoptions['widget_show_hits'] = strip_tags(stripslashes($_POST['mywidget-hits']));
if ( $options !== $newoptions ) {
$options = $newoptions;
update_option('most_read_widget_options', $options);
}
}
$title = htmlspecialchars($options['title'], ENT_QUOTES);
$quanti = htmlspecialchars($options['quanti'], ENT_QUOTES);
$limit = htmlspecialchars($options['limit'], ENT_QUOTES);
$widget_show_hits = htmlspecialchars($options['widget_show_hits'], ENT_QUOTES);
?>
<div>
<label for="mywidget-title" style="line-height:35px;display:block;"><?php _e('Title') ?>: <input style="width: 150px;" type="text" id="mywidget-title" name="mywidget-title" value="<?php echo $title; ?>" /></label>
<label for="mywidget-text" style="line-height:35px;display:block;"><?php _e('Show most read posts in', 'most_read'); ?> <input type="text" id="mywidget-text" name="mywidget-text" style="width: 30px;" value="<?php echo $quanti; ?>" /> <?php _e('days', 'most_read'); ?></label>
<label for="mywidget-limit" style="line-height:35px;display:block;"><?php _e('Show', 'most_read'); ?> <input type="text" id="mywidget-limit" name="mywidget-limit" style="width: 30px;" value="<?php echo $limit; ?>" /> <?php _e('posts in the sidebar', 'most_read'); ?></label>
<label for="mywidget-hits" style="display:block;"><input type="checkbox" id="mywidget-hits" name="mywidget-hits" value="yes" <?php if ($widget_show_hits == 'yes'){ echo 'checked'; } ?> /> <?php _e('Show hits near title', 'most_read'); ?><br />
(<?php _e('check this if you want to show hits near the post title in your sidebar', 'most_read'); ?>)</label>
<input type="hidden" name="mywidget-submit" id="mywidget-submit" value="1" />
</div>
<?php
}
register_sidebar_widget('Most Read Posts', 'ST4_most_read_widget');
register_widget_control('Most Read Posts', 'ST4_most_read_widget_control');
}
add_action('plugins_loaded', 'ST4_most_read_init_widgets');
function ST4_single_hits() {
global $wpdb, $posts;
$p_ID = $posts[0]->ID;
$actual_hits = $wpdb->get_var("SELECT hits FROM $wpdb->posthits WHERE post_ID='$p_ID'");
if (!$actual_hits){
$actual_hits = 0;
}
echo $actual_hits;
}
function ST4_hits(){
global $wpdb, $post;
$actual_hits = $wpdb->get_var("SELECT hits FROM $wpdb->posthits WHERE post_ID='$post->ID'");
if (!$actual_hits){
$actual_hits = 0;
}
echo $actual_hits;
}
function ST4_update_post(){
global $wpdb, $post;
if (is_single()){
$p_ID = $post->ID;
$mread_options = get_ST4_mostread_options();
$cookie_secs = $mread_options[read_seconds];
$cookie_label = 'ST4_read_post_'.$p_ID.'_ID';
if(!$_COOKIE[$cookie_label]) {
$actual_hits = $wpdb->get_var("SELECT hits FROM $wpdb->posthits WHERE post_ID='$p_ID'");
if (!$actual_hits){
$add = $wpdb->query("INSERT INTO $wpdb->posthits (post_ID, hits) VALUES ('$p_ID','1')");
$n_hits = 1;
} else {
$n_hits = $actual_hits + 1;
$upd = $wpdb->query("UPDATE $wpdb->posthits SET hits = '$n_hits' WHERE post_ID = '$p_ID'");
}
setcookie($cookie_label, 1, time() + $cookie_secs, COOKIEPATH, COOKIE_DOMAIN);
}
}
}
function ST4_mostread($last_days, $quanti='5', $widget_show_hits='yes'){
global $wpdb;
$sql = "SELECT p.post_title, p.post_date, st.post_ID, st.hits as cnt
FROM $wpdb->posthits st, $wpdb->posts p
WHERE p.ID = st.post_ID AND p.post_status = 'publish'
AND DATE_SUB(CURDATE(),INTERVAL $last_days DAY) < p.post_date
GROUP BY st.post_ID ORDER BY cnt DESC LIMIT 0, $quanti";
$output = $wpdb->get_results($sql);
if ($output) {
echo '<ul>';
foreach ($output as $line) {
$views = " (".($line->cnt).")";
$t = str_replace("'","'", $line->post_title);
echo "<li><a title='". $t . $ttviews . "' href='" . get_permalink($line->post_ID) . "'>".($line->post_title)."</a> ";
if ($widget_show_hits == 'yes') {
echo $views;
}
echo "</li>";
}
echo '</ul>';
} else {
echo '<ul><li>' . __('No results available', 'most_read') . '</li></ul>';
}
}
function ST4_install_most_read(){
global $wpdb;
$table_name = $wpdb->prefix . "most_read_hits";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "CREATE TABLE " . $table_name . " (
ID int(5) unsigned NOT NULL auto_increment,
post_ID int(5) NOT NULL default '0',
hits int(10) NOT NULL default '0',
PRIMARY KEY (ID)
);
";
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta($sql);
}
$most_read_options = array('read_seconds' => '172800');
update_option('MostReadOptions', $most_read_options);
}
function strTime($s) {
$d = intval($s/86400);
$s -= $d*86400;
$h = intval($s/3600);
$s -= $h*3600;
$m = intval($s/60);
$s -= $m*60;
if ($d) $str = $d;
if ($h) $str .= $h;
if ($m) $str .= $m;
if ($s) $str .= $s;
return $str;
}
function get_ST4_mostread_options() {
global $most_read_options_name;
$mread_options = get_option($most_read_options_name);
return $mread_options;
}
function ST4_mostread_options(){
global $most_read_options_name;
$mread_options = get_ST4_mostread_options();
?>
<div class="wrap">
<h2><?php _e('Most Read Options', 'most_read'); ?></h2>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
<p><?php _e('To avoid multiple counts of the same post by the same user, the plugin uses a cookie to count only the first hit.', 'most_read'); ?></p>
<p><?php _e('Cookie expires in', 'most_read'); ?>: <input type="text" size="3" name="most_read_options" value="<?php echo strTime($mread_options['read_seconds']); ?>" /> <?php _e('days', 'most_read'); ?>. </p>
<input type="hidden" name="action" value="update_most_read_options" />
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php
}
function ST4_mostread_update_settings(){
global $most_read_options_name, $wpdb;
if($_POST['action'] == 'update_most_read_options'){
$giorni = $wpdb->escape($_POST['most_read_options']);
$seconds = $giorni * 86400;
$most_read_options = array('read_seconds' => $seconds);
update_option($most_read_options_name, $most_read_options);
header('Location: '.get_bloginfo('wpurl').'/wp-admin/options-general.php?page=ST4_most_read.php&updated=true');
}
}
function ST4_mostread_menu(){
add_options_page(__('Most Read','most_read'), __('Most Read Options','most_read'), 8, basename(__FILE__), 'ST4_mostread_options');
}
add_action('template_redirect', 'ST4_update_post');
add_action('init', 'ST4_mostread_update_settings', 9999);
add_action('admin_menu', 'ST4_mostread_menu');
register_activation_hook( __FILE__, 'ST4_install_most_read' );
?>