<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Schnipsel - Code Schnipsel (Snippets) zu Wordpress, PHP, HTML, CSS, jQuery &#187; Function</title>
	<atom:link href="http://schnipsel.davidhellmann.com/tag/function/feed" rel="self" type="application/rss+xml" />
	<link>http://schnipsel.davidhellmann.com</link>
	<description>Code Schnipsel (Snippets) zu Wordpress, PHP, HTML, CSS, jQuery</description>
	<lastBuildDate>Tue, 08 Mar 2011 00:20:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>WordPress &#8211; Shortcodes erstellen</title>
		<link>http://schnipsel.davidhellmann.com/wordpress/wordpress-shortcodes-erstellen/64</link>
		<comments>http://schnipsel.davidhellmann.com/wordpress/wordpress-shortcodes-erstellen/64#comments</comments>
		<pubDate>Tue, 30 Jun 2009 06:38:23 +0000</pubDate>
		<dc:creator>David Hellmann</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Shortcodes]]></category>

		<guid isPermaLink="false">http://schnipsel.davidhellmann.com/?p=64</guid>
		<description><![CDATA[Wenn man zum Beispiel einen oft wiederkehrende Zeichenfolge hat und man diese nicht immer schreiben m&#246;chte von Hand k&#246;nnte man die mit Shortcodes machen. 1 2 3 4 5 6 &#60;?php function makebetterwebsites&#40;&#41; &#123; return 'Make Better Websites - Webseitengallery f&#252;r wundersch&#246;ner und eindrucksvolle Webseiten.'; &#125; &#160; add_shortcode&#40;'mbw', 'makebetterwebsites'&#41;; ?&#62; Jetzt m&#252;sste man in WordPress [...]]]></description>
			<content:encoded><![CDATA[<p>Wenn man zum Beispiel einen oft wiederkehrende Zeichenfolge hat und man diese nicht immer schreiben m&#246;chte von Hand k&#246;nnte man die mit Shortcodes machen.
</p>
<span id="more-64"></span>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000000; font-weight: bold;">function</span> makebetterwebsites<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'Make Better Websites - Webseitengallery für wunderschöner und eindrucksvolle Webseiten.'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mbw'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'makebetterwebsites'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>



<p>
Jetzt m&#252;sste man in WordPress bei einem Artikel (HTML Editor) einfach [mbw] einsetzen und es w&#252;rde der Text: "Make Better Websites - Webseitengallery f&#252;r wundersch&#246;ner und eindrucksvolle Webseiten." erscheinen. 
</p>
<p>
Da kommt mir gerade die Idee, ob es so vielleicht m&#246;glich w&#228;re ganze Codeschnipsel die man oft braucht (z. B. Letzte Artikel ausgeben) einfach in solche Shortcodes packen k&#246;nnte und somit in den Templates relativ wenig code hat. Wer kann was dazu sagen?
<br /><br />
<strong>***UPDATE***</strong><br />
Ein kurzer plausch mit <a href="http://www.bueltge.de">Frank</a> und es kam raus das das so nicht m&#246;glich w&#228;re aber er hat mich auf eine andere Sache gesto&#223;en die im grunde &#228;hnlich einfach ist :)
</p>]]></content:encoded>
			<wfw:commentRss>http://schnipsel.davidhellmann.com/wordpress/wordpress-shortcodes-erstellen/64/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>jQuery form input default value</title>
		<link>http://schnipsel.davidhellmann.com/jquery/jquery-form-input-default-value/27</link>
		<comments>http://schnipsel.davidhellmann.com/jquery/jquery-form-input-default-value/27#comments</comments>
		<pubDate>Wed, 29 Apr 2009 09:27:22 +0000</pubDate>
		<dc:creator>Bastian Winkler</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Formulare]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[jQuery Plugin]]></category>

		<guid isPermaLink="false">http://schnipsel.davidhellmann.com/?p=27</guid>
		<description><![CDATA[Ein Defaultvalue f&#252;r Input felder setzen mit jQuery 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 &#160; jQuery.fn.DefaultValue = function&#40;&#41; &#123; &#160; // Scope var elements = this; var args [...]]]></description>
			<content:encoded><![CDATA[<p>
Ein Defaultvalue f&#252;r Input felder setzen mit jQuery
</p>
<span id="more-27"></span>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">DefaultValue</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Scope</span>
		<span style="color: #003366; font-weight: bold;">var</span> elements <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> args <span style="color: #339933;">=</span> arguments<span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> c <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span>
			elements.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>				
&nbsp;
				<span style="color: #006600; font-style: italic;">// Default values within scope</span>
				<span style="color: #003366; font-weight: bold;">var</span> el <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003366; font-weight: bold;">var</span> def <span style="color: #339933;">=</span> args<span style="color: #009900;">&#91;</span>c<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
				el.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>def<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> def<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						el.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					el.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							el.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>def<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">DefaultValue</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Suchen&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


]]></content:encoded>
			<wfw:commentRss>http://schnipsel.davidhellmann.com/jquery/jquery-form-input-default-value/27/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Kategorie von der Startseite ausschlie&#223;en</title>
		<link>http://schnipsel.davidhellmann.com/wordpress/kategorie-von-der-startseite-ausschliessen/23</link>
		<comments>http://schnipsel.davidhellmann.com/wordpress/kategorie-von-der-startseite-ausschliessen/23#comments</comments>
		<pubDate>Fri, 24 Apr 2009 13:19:23 +0000</pubDate>
		<dc:creator>David Hellmann</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Function]]></category>

		<guid isPermaLink="false">http://schnipsel.davidhellmann.com/?p=23</guid>
		<description><![CDATA[Erm&#246;glicht das ausschlie&#223;en gewisser Kategorien von der Startseite. Kommt in die functions.php im Theme Ordner. 1 2 3 4 5 6 7 8 9 10 11 &#60;?php // Kategorie von Startseite ausschlie&#223;en function filter_posts&#40;&#41; &#123; global $wp_query; if&#40;is_home&#40;&#41;&#41; &#123; $wp_query-&#62;set&#40;'category__not_in',array&#40;49&#41;&#41;; &#125; &#125; &#160; add_action&#40;'pre_get_posts','filter_posts'&#41;; ?&#62;]]></description>
			<content:encoded><![CDATA[<p>
Erm&#246;glicht das ausschlie&#223;en gewisser Kategorien von der Startseite. Kommt in die <strong>functions.php</strong> im Theme Ordner.
</p>
<span id="more-23"></span>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">// Kategorie von Startseite ausschließen</span>
	<span style="color: #000000; font-weight: bold;">function</span> filter_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category__not_in'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">49</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pre_get_posts'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'filter_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>



]]></content:encoded>
			<wfw:commentRss>http://schnipsel.davidhellmann.com/wordpress/kategorie-von-der-startseite-ausschliessen/23/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Bestimmte Kategorien nicht im RSS Feed anzeigen lassen</title>
		<link>http://schnipsel.davidhellmann.com/wordpress/bestimmte-kategorien-nicht-im-rss-feed-anzeigen-lassen/22</link>
		<comments>http://schnipsel.davidhellmann.com/wordpress/bestimmte-kategorien-nicht-im-rss-feed-anzeigen-lassen/22#comments</comments>
		<pubDate>Thu, 23 Apr 2009 17:55:24 +0000</pubDate>
		<dc:creator>David Hellmann</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[RSS Feed]]></category>

		<guid isPermaLink="false">http://schnipsel.davidhellmann.com/?p=22</guid>
		<description><![CDATA[Eine Funktion die es erm&#246;glicht, dass gewisse Kategorien nicht im RSS Feed angezeigt werden. Das ganze kommt in die functions.php des aktiven Themes. 1 2 3 4 5 6 7 8 9 10 11 &#60;?php // Kategorie von RSS ausschlie&#223;en function fb_cat_exclude&#40;$query&#41; &#123; if &#40;$query-&#62;is_feed&#41; &#123; $query-&#62;set&#40;'cat','-49'&#41;; &#125; return $query; &#125; &#160; add_filter&#40;'pre_get_posts','fb_cat_exclude'&#41;; ?&#62;]]></description>
			<content:encoded><![CDATA[<p>
Eine Funktion die es erm&#246;glicht, dass gewisse Kategorien nicht im RSS Feed angezeigt werden. Das ganze kommt in die <strong>functions.php</strong> des aktiven Themes. 
</p>
<span id="more-22"></span>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">// Kategorie von RSS ausschließen</span>
	<span style="color: #000000; font-weight: bold;">function</span> fb_cat_exclude<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_feed</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'-49'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pre_get_posts'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'fb_cat_exclude'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


]]></content:encoded>
			<wfw:commentRss>http://schnipsel.davidhellmann.com/wordpress/bestimmte-kategorien-nicht-im-rss-feed-anzeigen-lassen/22/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jeder Kategorie ein eigenes Template zuweisen</title>
		<link>http://schnipsel.davidhellmann.com/wordpress/jeder-kategorie-ein-eigenes-template-zuweisen/10</link>
		<comments>http://schnipsel.davidhellmann.com/wordpress/jeder-kategorie-ein-eigenes-template-zuweisen/10#comments</comments>
		<pubDate>Tue, 21 Apr 2009 23:49:31 +0000</pubDate>
		<dc:creator>David Hellmann</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Single Post]]></category>
		<category><![CDATA[Template]]></category>

		<guid isPermaLink="false">http://schnipsel.davidhellmann.com/?p=10</guid>
		<description><![CDATA[Dieses Funktion erm&#246;glicht es, dass man f&#252;r jede Kategorie eine eigene single.php anlegen. Es wird die Kategorie-ID ausgelesen und dann kann man ganz einfach eine neue single.php erstellen in folgender Form: single-kategorie-ID.php was dann so ausschaut: single-3.php - dies w&#228;re dann das Template was f&#252;r alle Artikel genutzt werden w&#252;rde diese in der Kategorie 3 [...]]]></description>
			<content:encoded><![CDATA[<p>
Dieses Funktion erm&#246;glicht es, dass man f&#252;r jede Kategorie eine eigene single.php anlegen. Es wird die Kategorie-ID ausgelesen und dann kann man ganz einfach eine neue single.php erstellen in folgender Form: single-kategorie-ID.php was dann so ausschaut: single-3.php - dies w&#228;re dann das Template was f&#252;r alle Artikel genutzt werden w&#252;rde diese in der Kategorie 3 sind. Falls keine spezielle single.php f&#252;r einen bestimme Kategorie vorhanden ist wird die Standard single.php genutzt. Das ganze am besten in die <strong>functions.php</strong> im Themefolder.  
</p>
<span id="more-10"></span>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'single_template'</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$t'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'foreach( (array) get_the_category() as $cat ) { 
	if ( file_exists(TEMPLATEPATH . &quot;/single-{$cat-&gt;term_id}.php&quot;) ) 
		return TEMPLATEPATH . &quot;/single-{$cat-&gt;term_id}.php&quot;; } return $t;'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


]]></content:encoded>
			<wfw:commentRss>http://schnipsel.davidhellmann.com/wordpress/jeder-kategorie-ein-eigenes-template-zuweisen/10/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

