Avatar billede Slettet bruger
27. august 2008 - 16:21 Der er 9 kommentarer og
1 løsning

Stort startbogstav i dropdown boks (WordPress)

Hej,

Hvordan laver jeg så min WordPress dropdown boks (arkiv) starter alle måneder med stort bogstav istedet for lille som den gør nu?

Min html kode:

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td>

<form id="archiveform" action="">
<select name=\"archive-dropdown\" onChange='document.location.href=this.options[this.selectedIndex].value;'>
  <option value=\"\"><?php echo attribute_escape(__('Select Month')); ?></option>
  <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?></select>
</form>

</td>
</tr>
</table>
Avatar billede w13 Novice
27. august 2008 - 16:24 #1
Du bruger bare funktionen ucwords()
Avatar billede w13 Novice
27. august 2008 - 16:25 #2
F.eks. er det måske:

<?php echo attribute_escape(__('Select Month')); ?>

der skal rettes til:

<?php echo ucwords(attribute_escape(__('Select Month'))); ?>
Avatar billede Slettet bruger
27. august 2008 - 16:30 #3
w13: Har prøvet men den vil stadig ikke vise månederne med stort startbogstav. Min kode ser nu således ud:

<form id="archiveform" action="">
<select name=\"archive-dropdown\" onChange='document.location.href=this.options[this.selectedIndex].value;'>
  <option value=\"\"><?php echo ucwords(attribute_escape(__('Select Month'))); ?></option>
  <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?></select>
</form>
Avatar billede Slettet bruger
27. august 2008 - 16:36 #4
'Select Month' som er det første den står på altid være med stort 'S' nu (Har lige testet dette) hvor jeg bruger ucwords, men månederne som den nok henter fra "wp_get_archives" er stadig med lille startbogstav.
Avatar billede w13 Novice
27. august 2008 - 16:46 #5
Så skal ucwords() jo bruges i linjen:

<?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?>

i stedet.
Avatar billede w13 Novice
27. august 2008 - 16:46 #6
<?php ucwords(wp_get_archives('type=monthly&format=option&show_post_count=1')); ?>
Avatar billede Slettet bruger
27. august 2008 - 16:52 #7
Mystisk, det virker heller ik. :S ... Hmm, måske jeg bare må leve med lille startbogstav så.

<form id="archiveform" action="">
<select name=\"archive-dropdown\" onChange='document.location.href=this.options[this.selectedIndex].value;'>
  <option value=\"\"><?php echo ucwords(attribute_escape(__('Select Month'))); ?></option>
  <?php ucwords(wp_get_archives('type=monthly&format=option&show_post_count=1')); ?></select>
</form>
Avatar billede w13 Novice
27. august 2008 - 17:02 #8
Det skal nok bare skrives ind i wp_get_archives så. Problemet er jo, at måneden bliver echo'et inde i funktionen.
Avatar billede Slettet bruger
27. august 2008 - 17:57 #9
Tror jeg har fundet funktionen wp_get_archives men det er virkelig en jungle at gennemskue hvad der skal rettes for det virker?

-----------------------------------------------

function wp_get_archives($args = '') {
    global $wpdb, $wp_locale;

    $defaults = array(
        'type' => 'monthly', 'limit' => '',
        'format' => 'html', 'before' => '',
        'after' => '', 'show_post_count' => false
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );

    if ( '' == $type )
        $type = 'monthly';

    if ( '' != $limit ) {
        $limit = absint($limit);
        $limit = ' LIMIT '.$limit;
    }

    // this is what will separate dates on weekly archive links
    $archive_week_separator = '&#8211;';

    // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
    $archive_date_format_over_ride = 0;

    // options for daily archive (only if you over-ride the general date format)
    $archive_day_date_format = 'Y/m/d';

    // options for weekly archive (only if you over-ride the general date format)
    $archive_week_start_date_format = 'Y/m/d';
    $archive_week_end_date_format    = 'Y/m/d';

    if ( !$archive_date_format_over_ride ) {
        $archive_day_date_format = get_option('date_format');
        $archive_week_start_date_format = get_option('date_format');
        $archive_week_end_date_format = get_option('date_format');
    }

    //filters
    $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
    $join = apply_filters('getarchives_join', "", $r);

    if ( 'monthly' == $type ) {
        $query = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit";
        $key = md5($query);
        $cache = wp_cache_get( 'wp_get_archives' , 'general');
        if ( !isset( $cache[ $key ] ) ) {
            $arcresults = $wpdb->get_results($query);
            $cache[ $key ] = $arcresults;
            wp_cache_add( 'wp_get_archives', $cache, 'general' );
        } else {
            $arcresults = $cache[ $key ];
        }
        if ( $arcresults ) {
            $afterafter = $after;
            foreach ( $arcresults as $arcresult ) {
                $url    = get_month_link($arcresult->year,    $arcresult->month);
                $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
                if ( $show_post_count )
                    $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
                echo get_archives_link($url, $text, $format, $before, $after);
            }
        }
    } elseif ('yearly' == $type) {
        $query = "SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date DESC $limit";
        $key = md5($query);
        $cache = wp_cache_get( 'wp_get_archives' , 'general');
        if ( !isset( $cache[ $key ] ) ) {
            $arcresults = $wpdb->get_results($query);
            $cache[ $key ] = $arcresults;
            wp_cache_add( 'wp_get_archives', $cache, 'general' );
        } else {
            $arcresults = $cache[ $key ];
        }
        if ($arcresults) {
            $afterafter = $after;
            foreach ($arcresults as $arcresult) {
                $url = get_year_link($arcresult->year);
                $text = sprintf('%d', $arcresult->year);
                if ($show_post_count)
                    $after = '&nbsp;('.$arcresult->posts.')' . $afterafter;
                echo get_archives_link($url, $text, $format, $before, $after);
            }
        }
    } elseif ( 'daily' == $type ) {
        $query = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC $limit";
        $key = md5($query);
        $cache = wp_cache_get( 'wp_get_archives' , 'general');
        if ( !isset( $cache[ $key ] ) ) {
            $arcresults = $wpdb->get_results($query);
            $cache[ $key ] = $arcresults;
            wp_cache_add( 'wp_get_archives', $cache, 'general' );
        } else {
            $arcresults = $cache[ $key ];
        }
        if ( $arcresults ) {
            $afterafter = $after;
            foreach ( $arcresults as $arcresult ) {
                $url    = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
                $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
                $text = mysql2date($archive_day_date_format, $date);
                if ($show_post_count)
                    $after = '&nbsp;('.$arcresult->posts.')'.$afterafter;
                echo get_archives_link($url, $text, $format, $before, $after);
            }
        }
    } elseif ( 'weekly' == $type ) {
        $start_of_week = get_option('start_of_week');
        $query = "SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC $limit";
        $key = md5($query);
        $cache = wp_cache_get( 'wp_get_archives' , 'general');
        if ( !isset( $cache[ $key ] ) ) {
            $arcresults = $wpdb->get_results($query);
            $cache[ $key ] = $arcresults;
            wp_cache_add( 'wp_get_archives', $cache, 'general' );
        } else {
            $arcresults = $cache[ $key ];
        }
        $arc_w_last = '';
        $afterafter = $after;
        if ( $arcresults ) {
                foreach ( $arcresults as $arcresult ) {
                    if ( $arcresult->week != $arc_w_last ) {
                        $arc_year = $arcresult->yr;
                        $arc_w_last = $arcresult->week;
                        $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));
                        $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
                        $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
                        $url  = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_option('home'), '', '?', '=', $arc_year, '&amp;', '=', $arcresult->week);
                        $text = $arc_week_start . $archive_week_separator . $arc_week_end;
                        if ($show_post_count)
                            $after = '&nbsp;('.$arcresult->posts.')'.$afterafter;
                        echo get_archives_link($url, $text, $format, $before, $after);
                    }
                }
        }
    } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
        ('alpha' == $type) ? $orderby = "post_title ASC " : $orderby = "post_date DESC ";
        $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
        $key = md5($query);
        $cache = wp_cache_get( 'wp_get_archives' , 'general');
        if ( !isset( $cache[ $key ] ) ) {
            $arcresults = $wpdb->get_results($query);
            $cache[ $key ] = $arcresults;
            wp_cache_add( 'wp_get_archives', $cache, 'general' );
        } else {
            $arcresults = $cache[ $key ];
        }
        if ( $arcresults ) {
            foreach ( $arcresults as $arcresult ) {
                if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
                    $url  = get_permalink($arcresult);
                    $arc_title = $arcresult->post_title;
                    if ( $arc_title )
                        $text = strip_tags(apply_filters('the_title', $arc_title));
                    else
                        $text = $arcresult->ID;
                    echo get_archives_link($url, $text, $format, $before, $after);
                }
            }
        }
    }
}

----------------------------------------------------
Avatar billede w13 Novice
27. august 2008 - 21:35 #10
Jeg tror bare, du skal rette alle de steder, der står:

echo get_archives_link($url, $text, $format, $before, $after);

til:

echo ucwords(get_archives_link($url, $text, $format, $before, $after));
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester