Create a Category Page for one Specific Category and Exclude this Category from the Main Page in WordPress

This blog serves as my digital notebook for more than eight years and I use to to collect all sorts of things, that I think are worth storing and sharing. Mainly, I blog about tiny technical bits, but recently I also started to write about my life here in Innsbruck, where I try to discover what this small city and its surroundings has to offer. The technical articles are written in English, as naturally the majority of visitors understands this language. The local posts are in German for the same reason. My intention was to separate this two topics in the blog and lot let the posts create any clutter between languages.

Child Themes

When tinkering with the code of your WordPress blog, it is strongly recommended to deploy and use a child theme. This allows to reverse changes easily and more importantly, allows to update the theme without having to re-implement your adaptions after each update. Creating a child theme is very easy and described here. In addition I would recommend using some sort of code versioning tool, such as Git.

Excluding a Category from the Main Page

WordPress offers user defined categories out of the box and category pages for each category. This model does not fit well for my blog, where I have static pages and a time series of blog posts on the main page. In order to prevent that the posts about Innsbruck show up at the main page, the category ‘Innsbruck’ needs to be excluded. We can create or modify the file functions.php in the child theme folder and add the following code.

This adds a filter which gets executed before the posts are collected. We omit all posts of the category Innsbruck, by adding a minus as prefix of the category ID. Of course you could also lookup the category ID in the administration dashboard, by hovering with your mouse over the category name and save one database query.

A Custom Page Specific for one Category

In the second step, create a new page in the dashboard. This page will contain all posts of the Innsbruck category that we will publish. Create the file page.php in your child theme folder and use the following code:

In this code snippet, we define a set of arguments, which are used for filtering the posts of the desired category. In this example, I used the id of the Innsbruck category (91) directly. We define that we want to display posts only, 5 per page. An important aspect is the pagination. When we only display posts of one category, we need to make sure that Worpress counts the pages correctly. Otherwise the page would always display the same posts, regardless how often the user clicks on the next page button. The reason is that this button uses the global paged variable, which is set correctly in the example above.

The if conditional makes sure that only the pages from the Innsbruck category are displayed. The while loop then iterates over all posts and displays them. At the bottom we can see the navigational buttons for older and newer posts of the Innsbruck category.

Continue reading


Vom Patscherkofel via Zirbenweg auf die Viggarspitze, zur Glungezerhütte und via Tulfeinjöchl zur Tulfeinalm

Mit dem Zirbenwegticket (21€ inkl. Bustransfer) kommt man (wie bereits beschrieben) sehr bequem auf den Patscherkofel. Von dort geht es entlang dem sehr angenehmen Zirbenweg Richtung Osten. Am Wochenende ist dieser Weg sehr überlaufen, unter der Woche war es jedoch erwartungsgemäß sehr ruhig. Nach etwa drei Kilometern des leichten Auf-und- abs erreicht man eine Abzweigung, auf der die Glungezerhütte ausgeschrieben ist. Der Weg wird schmäler und auch etwas steiler, dafür aber auch schöner, denn man wandert über große Steinplatten, die vom Latschengewächs sehr schön eingerahmt werden.

glungetzer-karte

Nach einem weiteren Kilometer erreicht man die Viggarspitze, deren Gipfelkreuz weithin sichtbar ist. Ein serpentinenartiger Steig führt einen recht Steil zum Gipfel, der sich in 2305m Seehöhe befindet. Der Ausblick ist phänomenal, man überblickt das gesamte Inntal, die Nordkette, Innsbruck natürlich aber auch den Patscherkofel und den Stubaier Gletscher. Nach kurzer Rast kann man den Gipfel auch in Richtung Süden wieder verlassen, was jedoch ein wenig Trittsicherheit abverlangt. Entlang eines sehr schönen Weges über Wiesen erreicht man wieder den Ursprünglicben Pfad zum Glungezer. Diesem folgt man weitere 3 Kilometer bis man nach einem doch recht anstrengenden Anstieg die Glungezerhütte erreicht. Dabei handelt es sich um die höchste ÖAV Hütte Nordtirols. Die Hütte schmiegt sich spektakulär an den Berg und auch hier hat man einen fantastischen Ausblick, befindet sich die Hütte doch auf 2610m Höhe. Zur Stärkung gabs Glungezer-Spaghetti à la Kathmandu, die man empfehlen kann. Auch zum Glungezer Gipfel ist es nicht mehr weit.

Glungezer wird als “Glúnggezer” ausgesprochen, mit kurzem “u” und mit Doppel-gg. Der Name Glungezer bedeutet “unter Felsblöcken dahinfließendes ‘glucksendes’ Wasser” –  Schmelzwasser, das “gluggezen tut” (Lautmalerei)

Der Glungezer trägt also einen “Wassernamen, der zum Gipfel hinaufgewandert ist”, wie es die Namensforscher nennen.

(Quelle)

Nach einem prüfenden Blick auf unsere Wadeln, hätte uns der Hüttenwirt zwar am liebsten über den Steig herunter geschickt, wir haben uns aber dennoch für die gemütlichere Variante über den Panoramasteig gewählt und uns wieder nach unten gearbeitet, Hier wären Wanderstöcke doch empfehlenswert gewesen, es geht doch etwas in die Knie. Parallel zum Zirbenweg gelangt man dann letzendlich zur Tulfeinalm, hinter der sich der Schlepplift (Glungezer Sektion 2) der sich im Sommer zu einem etwas abenteuerlichen Einersessellift wandelt, befindet.

tulfein

Mit diesem Gelangt man nach einer beschaulichen Fahrt zum Doppelsessellift, der einen schlussendlich ins Tal nach Tulfes befördert. Von dort gilt es nur noch den Wanderbus Richtung Igls zu erwischen, der einen wieder an den Ausgangspunkt zurückbringt.

Continue reading


Persistent Data in a MySQL Docker Container

Running MySQL in Docker

In a recent article on Docker in this blog, we presented some basics for dealing with data in containers. This article will present another popular application for Docker: MySQL containers. Running MySQL instances in Docker allows isolating database infrastructure with ease.

Connecting to the Standard MySQL Container

The description of the MySQL docker image provides a lot of useful information how to launch and connect to a MySQL container. The first step is to create standard MySQL container from the latest available image.

This creates a MySQL container where the root password is set to secret. As the host is already running its own MySQL instance (which has nothing to do with this docker example), the standard port 3306 is already taken. Thus we publish utilise the port 3307 on the host system and forward it to the 3306 standard port from the container.

Connect from the Host

We can then connect from the command line like this:

We could also provide the hostname localhost for connecting to the container, but as the MySQL client per default assumes that a localhost connection is via a socket, this would not work. Thus when using the hostname localhost, we needed to specify the protocol TCP, wo that the client connects via the network interface.

Connect from other Containers

Connecting from a different container to the MySQL container is pretty straight forward. Docker allows to link two containers and then use the exposed ports between them. The following command creates a new ubuntu container and links to the MySQL container.

After this command, you are in the terminal of the Ubuntu container. We then need to install the MySQL client for testing:

The last command gives you a list of environment variables, among which is the IP address and port of the MySQL container.

You can then connect either manually of by providing the variables

If you only require a MySQL client inside a container, simply use the MySQL image from docker. Batteries included!

Continue reading


Persistent Docker Containers

Docker Fundamentals

Docker has become a very popular tool for orchestrating services. Docker it much more lightweight than virtual machines. For instance do containers not require a boot process. Docker follows the philosophy that one container serves only one process. So in contrast to virtual machines which often bundle several services together, Docker is built for running single services per container. If you come from the world of virtualised machines, Docker can be a bit confusing in the beginning, because it uses its own terminology. A good point to start is as always the documentation and there are plenty of great tutorials out there.

Images and Containers

Docker images serves as templates for the containers. As images and containers both have hexadecimal ids they are very easy to confuse. The following example shows step by step how to create a new container based on the Debian image and how to open shell access.

A shorter variant of creating and launching a new container is listed below. The run command creates a new container and starts it automatically. Be aware that this creates a new container every time, so assigning a container name helps with not confusing the image with the container. The command run is in particular tricky, as you would expect it to run (i.e. launch) a container only. In fact, it creates a new one and starts it.

Important Commands

The following listing shows the most important commands:

You can of course create your own images, which will not be discussed in this blog post. It is just important to know that you can’t move containers from your host so some other machine directly. You would need to commit the changes made to the image and create a new container based on that image. Please be aware that this does not include the actual data stored in that container! You need to manually export any data and files from the original container and import it in the new container again. This is another trap worth noting. You can, however,  also mount data in the image, if the data is available at the host at the time of image creation. Details on data in containers can be found here.

Persisting Data Across Containers

The way how Docker persists data needs getting used to in the beginning, especially as it is easy to confuse images with containers. Remember that Docker images serve only as the template. So when you issue the command sudo docker run ...  this actually creates a container from an image first and then starts it. So whenever you issue this command again, you will end up with a new container which does share any data with the previously created container.

Docker 1.9 introduced data volume containers, which allow to create dedicated data containers which can be used from several other containers. Data volume containers can be used for persisting data. The following listing shows how to create a data volume container and mount the volume in a container.

After we logged into the shell, we can see the data volume we mounted on the directory test-data:

We can navigate into that folder and create a 100 M data file with random data.

When we exit the container, we can see the file in the host file system  here:

We can use this volume transparently in the container, but it is not depending on the container itself. So whenever we have to delete to container or want to use the data with a different container, this solution works perfectly. Thw following command shows how we mount the same volume in an Ubuntu container and execute the ls command to show the content of the directory.

You can display a lot of usefil information about a container with the inspect command. It also shows the data container and where it is mounted.

We delete the ubuntu container and create a new one. We then start the container, open a bash session and write some test data into the directory.

When we check the Debian container, we can immediately see the written file, as the volume is transparently mounted.

Please be aware that the docker volume is just a regular folder on the file system. Writing from both containers the same file can lead to data corruption. Also remember that you can read and write the volume files directly from the host system.

Backups and Migration

Backing up data is also an important aspect when you use named data volumes as shown above. Currently, there is no way of moving Docker containers or volumes natively to a different host. The intention of Docker is to make the creation and destruction  of containers very cheap and easy. So you should not get too attached to your containers, because you can re-create them very fast. This of course is not true for the data stored in volumes. So you need to take care of your data yourself, for instance by creating automated backups like this sudo tar cvfz Backup-data-volume-test.tar.gz /var/lib/docker/volumes/data-volume-test and re-store the data when needed in a new volume. How to backup volumes using a container is described here.

Continue reading