Kategorier
PHP Timber Twig Wordpress

Tilføj custom filter til Timber/Twig

Nedenstående eksempel tilføjer et filter som kan bruges i twig templaten sådan:

{{ field.name | truncate_title }}

add_filter('get_twig', 'add_to_twig');

function add_to_twig($twig)
{
    $twig->addFilter('truncate_title', new Twig_Filter_Function('truncate_title'));
    return $twig;
}

function truncate_title($content)
{
    $content = Timber\TextHelper::trim_characters($content, 45);
    return $content;
}
Kategorier
Wordpress

WordPress dashboard standard menu items position

The default menu items has the following positions:

  • 2 Dashboard
  • 4 Separator
  • 5 Posts
  • 10 Media
  • 15 Links
  • 20 Pages
  • 25 Comments
  • 59 Separator
  • 60 Appearance
  • 65 Plugins
  • 70 Users
  • 75 Tools
  • 80 Settings
  • 99 Separator
Kategorier
htaccess Wordpress

WordPress: Vis billeder fra live server

Bruges for at vise billeder fra live server på lokalt setup.

# BEGIN Clever hack to show production images on dev site

# Force image styles that have local files that exist to be generated.
RewriteCond %{REQUEST_URI} ^/app/uploads/.*$
RewriteCond %{DOCUMENT_ROOT}/app/uploads/%1 -f
RewriteRule ^(.*)$ $1 [QSA,L]
# Otherwise, send anything else that's in the files directory to the production server.
RewriteCond %{REQUEST_URI} ^/app/uploads/.*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://yourdomain.com/$1 [QSA,L]

# END Clever hack to show production images on dev site
Kategorier
CMS PHP Wordpress

Vis alle tilgængelige terms i custom taxonomy

Dette viser alle tilgængelige taxonomy terms og ikke kun de valgte. (Alle dem som er i brug på en post). Er der mere end 1, adskilles de med en skråstreg.

<?php 
    $terms = get_terms("custom_taxonomy_navn");
    $count = count($terms);
    $i = 0; 
    if ( $count > 0 ){
        foreach ( $terms as $term ) {
            if ( $i == 0) {
                echo $term->name;
            } else {
            echo " / " . $term->name;
            }
            $i++;
            }
} 
?>