Display posts by tags

Display posts only with a tag, and sort alphabetical first by tag and then by post.

  1. Get tags used only by custom post type links.
  2. Only output name of the tag if it has a post attached to it.
  3. For each tag name output all the posts (title and special field type notes).
<?php
        $tags = get_tags();
        foreach ( $tags as $tag )
            {
            $tag_query = new WP_Query( array(
                'post_type' => array('links'),
                'tag_id' => $tag->term_id,
                'posts_per_page' => -1,
                'orderby' => 'title',
                'order' => 'ASC',
                'no_found_rows' => true,
                ) );
            if( $tag_query->have_posts() )
                {
                    echo '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">';
                        echo '<h3>' .$tag->name. '</h3>';
                    echo '</div><!-- .col -->';
                }
        while ( $tag_query->have_posts() ) : $tag_query->the_post(); ?>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12"><!-- link -->
                <a href="<?php echo types_render_field("links-url", array("output"=>"raw")); ?>">
                    <p><?php the_title(); ?>
                        <?php if(types_render_field('links-notes', array('raw'=>'true'))){ ?>
                            <span>(<?php echo types_render_field("links-notes", array("output"=>"HTML")); ?>)</span>
                    <?php } ?>
                    </p>
                </a>
            </div><!-- .col -->
             <?php endwhile; } ?>
<?php wp_reset_postdata(); ?>

The output result:

display-posts-by-tags_2016-02-20_13.22.43

Accept comma in tag cloud

Put in functions.php

https://wordpress.org/support/topic/adding-tags-with-commas-in-them

// filter for tags with comma
//  replace '--' with ', ' in the output - allow tags with comma this way
//  e.g. save tag as "Fox--Peter" but display thx 2 filters like "Fox, Peter"
if(!is_admin()){ // make sure the filters are only called in the frontend
    function comma_tag_filter($tag_arr){
        $tag_arr_new = $tag_arr;
        if($tag_arr->taxonomy == 'post_tag' && strpos($tag_arr->name, '--')){
            $tag_arr_new->name = str_replace('--',', ',$tag_arr->name);
        }
        return $tag_arr_new;    
    }
    add_filter('get_post_tag', 'comma_tag_filter');
    function comma_tags_filter($tags_arr){
        $tags_arr_new = array();
        foreach($tags_arr as $tag_arr){
            $tags_arr_new[] = comma_tag_filter($tag_arr);
        }
        return $tags_arr_new;
    }
    add_filter('get_terms', 'comma_tags_filter');
    add_filter('get_the_terms', 'comma_tags_filter');
}

Disable and remove left menu in Dashboard

Add it to functions.php

/**
 * Remove a top level admin menu in Dashboard
 *
 * http://codex.wordpress.org/Function_Reference/remove_menu_page
 */
function remove_menus(){
 
  remove_menu_page( 'edit.php' );                   //Posts
  remove_menu_page( 'edit-comments.php' );          //Comments
  remove_menu_page( 'tools.php' );                  //Tools
 
}
add_action( 'admin_menu', 'remove_menus' );

Remove a left Dashboard menu item

How to remove left menu items in Dashboard.

For removing submenu item: http://codex.wordpress.org/Function_Reference/remove_submenu_page

Add to functions.php

Below removes Posts, Comments, and Tools.

/**
 * Remove a top level admin menu in Dashboard
 *
 * http://codex.wordpress.org/Function_Reference/remove_menu_page
 */
function remove_menus(){
 
  remove_menu_page( 'edit.php' );                   //Posts
  remove_menu_page( 'edit-comments.php' );          //Comments
  remove_menu_page( 'tools.php' );                  //Tools
 
}
add_action( 'admin_menu', 'remove_menus' );

Before

Default WordPress Dashboard left menu

Default WordPress Dashboard left menu

After

Edited WordPress Dashboard left menu

Edited WordPress Dashboard left menu

Resources

http://codex.wordpress.org/Function_Reference/remove_menu_page

As a plugin: http://premium.wpmudev.org/blog/how-to-remove-menus-from-the-wordpress-dashboard/

Redirect med htaccess

Redirect af besøgende til en specifik side, med undtagelse af specifikke IP-adresser.

Du finder din ip-adresse ved fx at bruge Google: what is my ip

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN redirect
RewriteEngine on
# home
RewriteCond %{REMOTE_ADDR} !^192\.198\.0\.1
# work
RewriteCond %{REMOTE_ADDR} !^192\.198\.0\.2
RewriteCond %{HTTP_HOST} ^domain.dk$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.dke$
RewriteRule ^(.*)$ http://domain.dk/midlertidig-side/$1 [R=307,L]
# END redirect

301 – permanent redirect
307 – midlertidig redirect (det samme som 302)

Foundation5: Første post i WP med anden CSS formatering

Ikke den mest elegante løsning, for at vise første post med anden formatering med Foundation 5 – men det virker. Desuden kan du let redigere i det, hvis du kender lidt til WordPress Codex.

PHP (i fx. index.php):

    <div class="row site-content first-post">
        <div class="large-12 columns">
            <?php $the_query = new WP_Query( 'showposts=1' ); ?>
            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
            <a href="<?php the_permalink() ?>">
                <div>
                    <h2><?php the_title(); ?></h2>
                    <p><?php the_post_thumbnail('thumbnail'); ?></p>
                    <p><?php echo substr(get_the_excerpt(), 0,230); ?></p>
                    <!-- <p><?php echo substr(strip_tags($post->post_content), 0, 250);?></p> -->
                </div>
            </a>
            <?php endwhile;?>
        </div>
    </div><!-- #row site-content -->
    <div class="row site-content posts">
        <div class="large-4 medium-4 columns">
            <?php $the_query = new WP_Query( 'posts_per_page=1&offset=1' ); ?>
            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
            <a href="<?php the_permalink() ?>">
                <div>
                    <h2><?php the_title(); ?></h2>
                    <p><?php the_post_thumbnail('thumbnail'); ?></p>
                    <p><?php echo substr(get_the_excerpt(), 0,230); ?></p>
                    <!-- <p><?php echo substr(strip_tags($post->post_content), 0, 250);?></p> -->
                </div>
            </a>
            <?php endwhile;?>
        </div>
        <div class="large-4 medium-4 columns">
            <?php $the_query = new WP_Query( 'posts_per_page=1&offset=2' ); ?>
            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
            <a href="<?php the_permalink() ?>">
                <div>
                    <h2><?php the_title(); ?></h2>
                    <p><?php the_post_thumbnail('thumbnail'); ?></p>
                    <p><?php echo substr(get_the_excerpt(), 0,230); ?></p>
                    <!-- <p><?php echo substr(strip_tags($post->post_content), 0, 250);?></p> -->
                </div>
            </a>
            <?php endwhile;?>
        </div>
        <div class="large-4 medium-4 columns">
            <?php $the_query = new WP_Query( 'posts_per_page=1&offset=3' ); ?>
            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
            <a href="<?php the_permalink() ?>">
                <div>
                    <h2><?php the_title(); ?></h2>
                    <p><?php the_post_thumbnail('thumbnail'); ?></p>
                    <p><?php echo substr(get_the_excerpt(), 0,230); ?></p>
                    <!-- <p><?php echo substr(strip_tags($post->post_content), 0, 250);?></p> -->
                </div>
            </a>
            <?php endwhile;?>
        </div>
    </div><!-- #row site-content -->

CSS:

body.home .first-post div a div,
body.home .posts div a div {
    padding: 25px;
    margin: 15px;
    background: #fff;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border-top: 1px solid #ECEDEE;
    border-right: 1px solid #D6D7D8;
    border-bottom: 1px solid #C2C3C3;
    border-left: 1px solid #D6D7D8;
background-color: transparent;
background-image: -webkit-gradient(
    linear,
    left top,
    left bottom,
    color-stop(0, #F6F6F6),
    color-stop(0.35, #FFFFFF));
background-image: -o-linear-gradient(top , #F6F6F6 0%, #FFFFFF 35%); /* Opera */
background-image: -moz-linear-gradient(top , #F6F6F6 0%, #FFFFFF 35%) ;/* Mozilla Firefox */
background-image: -webkit-linear-gradient(center top , #F6F6F6 0%, #FFFFFF 35%); /* Webkit (Chrome 11+) */
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #F6F6F6), color-stop(0.35, #FFFFFF)); /* Webkit (Safari/Chrome 10) */
background-image: -ms-linear-gradient(top , #F6F6F6 0%, #FFFFFF 35%); /* IE10 */
background-image: linear-gradient(top , #F6F6F6 0%, #FFFFFF 35%); /* Proposed W3C Markup */
background-repeat: repeat;
background-attachment: scroll;
background-position: 0% 0%;
background-clip: border-box;
background-origin: padding-box;
background-size: auto auto;
/* inside white border */
box-shadow: 0px 1px 0px 0px #FFF inset, 1px 0px 0px 0px #FFF inset, -1px 0px 0px 0px #FFF inset, 0px -1px 0px 0px #FFF inset, 0px 2px 0px 0px rgba(0, 0, 0, 0.03), 0px 1px 0px 0px rgba(0, 0, 0, 0.05);}
body.home .first-post div a div {margin-top: 0;}
    body.home .first-post div a div h2 {font-size: 2.1em;}
    body.home .first-post div a div p {font-size: 1.15em;}
body.home .first-post div a div,
body.home .posts div a:first-child div {margin-left: 0;}
body.home .first-post div a div,
body.home .posts div a:last-child div {margin-right: 0;}
body.home .first-post div a:hover div,
body.home .posts div a:hover div {
    background-color: #F6F6F6;
    background-image: -moz-linear-gradient(center top , #efefef 0%, #FFF 100%);}
body.home .first-post div a:hover div h2,
body.home .posts div a:hover div h2 {
    color: #000;}

Resultatet:

Foundation 5

Thumbnail

<?php if ( has_post_thumbnail()) : ?> <!-- check if the post has a Post Thumbnail assigned to it. -->
    <div class="listThumb"><?php the_post_thumbnail('thumbnail'); ?></div>
<?php endif; ?>
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
    the_post_thumbnail('thumbnail'); }
?>

Content Deployment for WordPress

From staging (or development) to production (or live) server.

Candidates: http://wplift.com/wordpress-development-site

RAMP (solution)
http://crowdfavorite.com/ramp/

5 Quick and Dirty Steps (the dirty way)
http://archonic.com/blog/web-mastery/wordpress-staging-in-5-step/

DeployMint (solution for Multisite)
http://premium.wpmudev.org/blog/introducing-deploymint-a-staging-and-deployment-system-made-for-wordpress-multisite/