Webdesign – go41

individuelles und professionelles Webdesign, Programmierung und Internetmarketing

February 22, 2011
Keine Kommentare

WordPress SELECT query einen Beitrag ausschliessen

Will man einen bestimmten Beitrag oder eine Seite nicht im Loop von WordPress anzeigen, gibt es einige Möglichkeiten.
Sofern man man die ID des Beitrags kennt, nimmt man am einfachsten ‘continue’, um diese $post->ID zu überspringen.
Man nimmt sich eine Vorlage seines Themes welche mehrere Beiträge darstellt. Dies sind z.B. index.php, archive.php, tag.php, category.php oder auch search.php.
Hier sucht man nach dem Loop, der normalerweise so anfängt:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

wichtig ist der Teil

the_post(); ?>

nach welchem man eine Zeile einfügt:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php  if( $post->ID == '5' ) continue; ?>

diese neue Zeile lässt den Loop den Beitrag mit der ID 5 aus, springt also darüber um mit dem nächsten Beitrag weiter zu machen.

Wie das in einer SELECT Query funktioniert  findet man hier:

wordpress query exclude one post or page in the loop

oder als Filter nach einem anderen Verfahren bei Bueltge hier Beiträge aus dem Suchergebnis von WordPress ausschließen

April 15, 2010
5 Kommentare

Wer darf was? Benutzergruppen in WordPress

Die Benutzerverwaltung von WordPress zwingt mich immer wieder danach zu suchen, welcher Benutzer was tun darf.

Da findet man auf doku.wordpress-deutschland.org Benutzerrollen Bezeichnungen wie:

Zusammenfassung der Rollen

  • Administrator – Jemand, der Zugang hat zu allen Features der WordPress-Installation
  • Editor – Jemand, der Beiträge veröffentlichen und bearbeiten kann. Dieses gilt auch für Fremde Beiträge und Kommentare
  • Author – Jemand, der eigene Beiträge veröffentlichen und bearbeiten kann.
  • Contributor – Jemand, der eigene Beiträge verfassen und bearbeiten, diese aber nicht veröffentlichen kann.
  • Subscriber – Jemand, der Kommentare lesen und schreiben kann und den Newsletter empfängt.

Bei mir im Dashboard heissen die aber:

Abonnent, Mitarbeiter, Autor, Redakteur und Administrator

Wer darf nun was?

Der Abonnent

Der Abonnent hat stark eingeschränkte Rechte.
Nach dem Login bekommt er eine Übersicht über ‘Aktuell’, ‘Letzte Kommentare’, ‘Eingehende Links’ und ‘Feeds’.
Er hat nicht die Möglichkeit, neue Artikel oder Seiten zu erstellen.
Der Abonnent kann nur sein eigenes Profil bearbeiten.
Er kann zwar auch den WYSIWYG-Editor aktivieren, hat darauf jedoch keinen Zugriff.

Der Mitarbeiter

Der Mitarbeiters bekommt im Dashboard zusätzlich das Modul “QuickPress” zum schnellen Schreiben von Artikeln. Er hat wie der Abonnent keine Erlaubnis Seiten zu verfassen.
Die Artikel des Mitarbeiters müssen vom Redakteur oder Administrator freigeschaltet werden. Mitrabeiter können keine neuen Kategorien erstellen.
Der Mitarbeiter darf nur eigene Artikel editieren, zudem kann er keine Dateien hochladen und keine Bilder oder Dateien in seine Artikel einbinden.
Der Mitarbeiter hat nicht die Möglichkeit, Kommentare zu moderieren.

Der Autor

Der Autor darf wie der Mitabeiter eigene Artikel verfassen, aber auch keine Seiten und keine Kategorien erstellen.
Er kann jedoch selbst bestimmen, welchen Status der Artikel hat, also Sichtbarkeit und den Zeitpunkt der Veröffentlichung.
Er darf Bilder, Dateien und andere Medien in die Mediathek hochladen und in seine Artikel einfügen.
Kommentare zu seinen Artikeln kann er bearbeiten und ändern.
Er kann ‘Press This’ benutzen. Das ist ein Bookmarklet (Link), welches eine kleine Anwendung lädt, die im Browser läuft und es erlaubt, Artikel im Browser zu schreiben und verschiedene Sachen aus dem Web zu übernehmen.

Der Redakteur

Der Redakteur vertritt im Prinzip den Administrator.
Er kann wie der Administrator Artikel, Seiten und Kategorien und Tags erstellen und bearbeiten.
der Redakteur darf Links bearbeiten und hinzufügen.
Er schaltet die Beiträge von Mitarbeitern frei und veröffentlicht diese.
Er kann Kommentare und Beiträge im gesamten Blog bearbeiten und verändern oder löschen, abgesehen von Inhalten welche der Administrator erstellt hat.
Der Redakteur kann das ‘Design’ des Blogs nicht beeinflussen oder ändern.

Der Administrator

Der Administrator hat Zugriff auf alle Einstellungen einer WordPress Seite.
Er kann das Theme bestimmen, Plugins installieren, neue Benutzer hinzufügen und Inhalte des Blogs exportieren oder importieren.

Als alleiniger Benutzer eines eigenen WordPress Blogs hat man meist die Rolle des Administrators.

Empfehlenswerter Link zu einer Beschreibung der Benutzergruppen:

Benutzergruppen in WordPress auf WordPress-Buch.de

May 14, 2009
2 Kommentare

Google, Adsense, Googlemail und youtube so langsam heute

Heute ist mal wieder so ein Tag, wo Google nicht zu erreichen ist und Websites, die Adsense nutzen, fast nicht laden.

Geht das nur mir so oder haben andere dasselbe Problem?

Youtube und Feedburner sind (zumindest von Deutschland aus) auch nicht erreichbar.

Schlägt da etwa die Netzsperre zu und bald sieht man statt Google nur noch das Stopp Zeichen?

March 3, 2009
5 Kommentare

List one latest post per category on frontpage view

I will give you here a code to list only one post per selected category. You could include this code into your index.php to query for the last posts of the categories you put into this code.
The first and the last line makes the post appear only on first page.

In the array of categories are six numbers now which you have to replace with the category IDs of your categories. It could be more or less, order them as you wish.

<?php if(!is_paged()) { // display only on page one if is not paged ?>
<?php $display_categories = array(8,5,4,6,7,3); foreach ($display_categories as $frontcats) { ?>
<?php $catposts = get_posts("showposts=1&cat=$frontcats"); foreach($catposts as $post) : setup_postdata($post); ?>
<h3 class=cat_title><a href="<?php echo get_category_link($frontcats);?>"><?php $this_category = get_category($frontcats); ?><?php echo $this_category->cat_name; ?> &raquo;</a></h3>
<div class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div>
<div class="meta"><?php the_time('j M Y') ?> | <?php comments_popup_link('No Comment', 'One Comment', '% Comments');?></div>
<?php	$values = get_post_custom_values("Image");if (isset($values[0])) { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<img src="<?php echo $values[0]; ?>" alt="<?php the_title(); ?>" /></a>
<?php } //end of image if set in custom field ?>
<?php the_excerpt(); ?>
<?php endforeach; // end of post ?>
<?php } ?>
<?php } // end of FIRST PAGE ?>

Actually I made this query for Arthemia theme, if you want you find the complete modified index.php renamed as arthemia_onepostpercat_index.txt here:

arthemia index.php modified to dispay one post per category on first page

This file is an Arthemia index.php and will show on the first page only one post of each selected category.

Pagination should work and will show you on page two the list of posts as you set them in the theme. Here you are again free to choose any category to exclude as normally done in this theme.

addbetween

March 1, 2009
5 Kommentare

Add Adsense between some Posts in WordPress

In WordPress on the frontpage you have normally a flow of posts.

I want to show you how to put any advertising link or Adsense code between one or more of this posts.

We are going to edit the index.php for this, so please make a BACKUP of this file before starting to change anything!!

We will do this by setting a post counter in front of the loop
$postno = 1
inserting the add code inside the loop
if ($postno == 3) do stuff
and make the postcounter count up one digit for every post
$postno++;

In Detail:
Take the index.php of your theme and find:

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>

place the counter start between this two lines like this:

<?php if (have_posts()) : ?>
<?php $postno = 1; ?>
<?php while (have_posts()) : the_post(); ?>

as we are going to place to add codes after the first and the third post we find the next:

<?php endwhile; ?>

and insert my suggested code just above this endwhile:

<?php if ($postno == 1) { ?><div align="center" style="margin-bottom: 10px;">
AdSense Code below post No. one replace with your code
</div><?php } ?>
<?php if ($postno == 3) { ?><div align="center" style="margin-bottom: 10px;">
AdSense Code below post No. three replace with your code
</div><?php } ?>
<?php $postno++; ?>

I styled this code to center on the page and give some space below, you are free to remove or change this div style.

There are some themes like Arthemia by Michael Jubel which use an other query for posts, so you will not be able to find the if (have_posts()) : part in there.

In a query like in that theme you should look for:

<?php
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("cat=-27,-28&paged=$page&posts_per_page=5"); ?>
<?php $postno = 1; ?>
<?php while (have_posts()) : the_post(); ?>

and place the counter start before while (have_posts()) : the_post(); – I did this here already.

The code to call the add code and count up one by one (as before) is placed in the same way as in default theme before the next endwhile; after the div before, it should look like this:

<?php the_excerpt(); ?>
</div>
</div>
<!-- new code start -->
<?php if ($postno == 1) { ?><div align="center" style="margin-bottom: 10px;">
AdSense Code below post No. one replace with your code
</div><?php } ?>
<?php if ($postno == 3) { ?><div align="center" style="margin-bottom: 10px;">
AdSense Code below post No. three replace with your code
</div><?php } ?>
<?php $postno++; ?>
<!-- new code end -->
<?php endwhile; ?>
<div class="navigation">

happy coding…

filezilla_explained

February 7, 2009
Keine Kommentare

Keep all your WordPress files on your PC with FileZilla

I see many WordPress user editing their files online with the theme editor. Doing something wrong with this it is hard to step back or restore your original theme files.

I never edited any files online but prefer to use a ftp client to access any files on my host.

Using FileZilla ‘the free ftp solution’ I can work like using any filemanager or explorer on my machine, have two windows side by side with the full tree and files on my host and the very same files on my pc as backup at home.

To get access to your site using ftp depends a bit on your hosting company, in the help files there you should be able to find out the ftp-link, username and password you have to use.

After installing FileZilla go to the server manager window and enter the required data in there. Actually very easy and after this connect to your site.  -> SEE UPDATE below regarding FileZilla Servermanager and password security!!

On one side of your screen you will see the root folders and files on the host, on the other side of the screen you see files and folders of your machine.

I suggest creating on your machine a folder called ‘websites’ and in there create another folder with the site you are just browsing via ftp.

Having done this, select all files and folders on your host and drag them to the site folder you created on your pc.

Now all your files, folders and subfolders are being copied to your pc.

It should look similar to this: (here FileZilla in German…)

—————–
You can tell Filezilla in server manger extended settings for this site to use a start folder, so use just this folder as start folder for that site and on connect the ftp client will show you two trees as above.

Double Clicking on a folder will show you the content of this folder, so go and explore your hosted files on you own machine.

In wp-content you find a plugins folder and the themes folder with subfolder of your plugins and themes.

Editing a file in your theme just right click it, choose edit and do your changes in the editor window. After saving locally FileZilla will ask you to upload the changed file automatically! But before clicking on ok, be sure to have the same folders in both windows open, otherwise it could happen that you find your sidebar.php in the root of the host and wonder that there is no change in what you edited.

One more advantage of keeping ALL WordPress files locally is, that you can easily switch the host by uploading all of the files to another server, putting a backup of you sql database there and the site will run on a new host (as soon you have changed DNS entries)

UPDATE JANUARY 2011: I do not recommend to use the Servermanager of FileZilla to store passwords of your site!! There are trojans around which could infect your machine just by surfing on an infected site.

This trojan virus could read your stored FileZilla Passwords and login, send them out and access your site to insert a malicious code into your files on the server. Look here for details:

site hacked: iframe src zxstats or bali-planet com script var zaee= on www.blogdot.de

February 2, 2009
15 Kommentare

list pages custom styling in arthemia category bar

Some users of of arthemia theme would like to display pages instead of categories in the category bar of this theme.

This bar has a custom styling for each of the 5 categories displayed.

What we are going to do is take off the list of categories and replace this list with a list of pages.
The  bar is created in index.php of arthemia theme and I refer to this file with the given styling.

From line 52 to line 70 (if unmodified) you find:

<div id="middle" class="clearfloat">
<img src="<?php echo get_option('home'); ?>/wp-content/themes/arthemia/images/category.png" class="clearfloat" alt="" />
--------------
All stuff in here we are replacing by the code given below!!
The image category.png you can change to what you like or remove this whole line too
--------------
</div>
<?php } ?>
<div id="bottom" class="clearfloat">

Let’s come to the replacement:

We insert this:
<?php
$pages = get_pages(); $i = 1;
foreach ($pages as $page) { ?>
<div id="cat-<?php echo $i; ?>" class="category">
<span class="cat_title"><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></span>
</div>
<?php $i++; } ?>

to call all pages and give them the style of the categories we had before.

Now it could be you have more than 5 pages or you do not want to display some of them. I suggest using the ‘include’ parameter and include exactly 5 of your pages.

The second line of this code could look like this:

$pages = get_pages('include=2,41,42,132,134'); $i = 1;

here I included the pages with IDs of 2 and 41 etc, just five of them to fit in

To list subpages or even excerpt of that pages – there is sure a way…

Update to get a description like there is a description for categories in this theme:

To get a description for each page we show in the category bar of arthemia we use a custom field as you have to use for images in posts.

Edit your pages where you want to get a short description and scroll in page editor down to ‘Custom Fields’

In “Add a new custom field:” under Key you enter ‘ pagedesc ‘ (just eight letters, no hyphen) and under Value any text you like to have as description for that page.

To be able to see this description you have to insert an updated code, actually same as above but with a query for this new created field and a command to echo it if it is there:

Full updated code here:

<?php
$pages = get_pages('include=2,41,42,132,134'); $i = 1;
foreach ($pages as $page) { ?>
<div id="cat-<?php echo $i; ?>" class="category">
<span class="cat_title"><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></span>
<?php if(get_post_meta($page->ID, "pagedesc", true)){ ?>
<a href="<?php echo get_page_link($page->ID) ?>"><?php $key="pagedesc"; echo get_post_meta($page->ID, $key, true); ?></a>
<?php } ?>
</div>
<?php $i++; } ?>

happy coding, give a comment if it is not working…

Another update: Sort the page entries as you like:
insert in this line:

$pages = get_pages('include=2,41,42,132,134'); $i = 1;

the parameter &sort_column=menu_order like this:

$pages = get_pages('include=2,41,42,132,134&sort_column=menu_order'); $i = 1;

then adjust in edit page on the right side under ‘order’ to give a value like first page in that row give 2, second one 4 third the 6,

it’s just like playing games as you have to try.

January 11, 2009
4 Kommentare

List some pages with content in WordPress

To list pages in WordPress you normally take this: <?php wp_list_pages(); ?>

But how to display some pages with the_content or the_excerpt?

I didn’t find a way to query specified pages by page_id and run a foreach loop, so we are going to get the pages one by one in separate queries and loops for each page.

Important is to rewind the query after the run by inserting this: <?php rewind_posts();?>

A simple query for three different pages plus title and including the excerpt I show you here: Weiterlesen →

December 13, 2008
15 Kommentare

List subcategories in category bar of arthemia theme

In the WordPress theme Arthemia theme by Michael Jubel is a wide category bar displaying 5 categories and their description.

Users of this theme having sub-categories will normally not see them on this bar. I will show you how to get sub-categories displayed if there are in different styles.

Let’s talk about the free Arthemia Magazine Style WordPress Theme first:

The category bar is displayed by a call in index.php between the line 49:
div id=”cat-…
and the line 58:
/div
The line 56 (span class=”cat_title”) displays the main category title, we leave it untouched
In line 57 the category description is echoed: “echo category_description”

The code I give you now will check if the displayed category has children (subcategories) and if there are it will list all of them. If there are no sub-categories, it will display nothing.

The code to insert below or instead of the category description and before the following /div is here:

<?php $sub_categories = wp_list_categories("echo=0&show_count=1&title_li=&show_count=0&style=none&use_desc_for_title=0&child_of=$category"); if ($sub_categories != "No categories") { ?>
<?php wp_list_categories("show_count=1&title_li=&show_count=0&style=none&use_desc_for_title=0&child_of=$category"); ?>
<?php } ?>

This code will give you links to your subcategories for each category displayed in the category bar. There is a <br /> tag inserted between each link.

To get the subcategories inserted in a list style you could use this code instead, getting -ul-li-li-ul around links:

<?php $sub_categories = wp_list_categories("echo=0&show_count=1&title_li=&show_count=0&style=none&use_desc_for_title=0&child_of=$category"); if ($sub_categories != "No categories") { ?>
<ul class="subcats"><?php wp_list_categories("show_count=1&title_li=&show_count=0&use_desc_for_title=0&child_of=$category"); ?></ul>
<?php } ?>

Using the list-stylecode you can style the way how the ul class subcats get displayed.

You could add anywhere into your style.css the following:

ul.subcats {list-style: none;}

with this entry in style.css you get the list-bullets removed from the sub-category list.

Yes, there are also users having the Arthemia Premium theme, they have to look in header.php and use this code (Premium only!! in header.php below echo category_description($cp_pC) close to the end of that file)

<?php $sub_categories = wp_list_categories("echo=0&show_count=1&title_li=&show_count=0&style=none&use_desc_for_title=0&child_of=$cp_pC"); if ($sub_categories != "No categories") { ?>
<ul class="subcats"><?php wp_list_categories("show_count=1&title_li=&show_count=0&use_desc_for_title=0&child_of=$cp_pC"); ?></ul>
<?php } ?>

Style the ul class subcats to get the desired results…