Ondersteuning » Thema en CSS/opmaak » Post theme aanpassen per categorie

  • Ik heb een vraag betreft CSS en PHP. Ik wil graag dat mijn post in een bepaalde categorie anders worden weergegeven als in alle andere categorien. Op de hoofdpagina moeten het de volledige post zijn maar in de categorie (bijv: headlines) moeten het alleen de titel en de datum zijn. Hoe kan ik dit het beste realiseren? ik heb al gezocht naar plugins. Bij voorbaat dank.

4 reacties aan het bekijken - 1 tot 4 (van in totaal 4)
  • Thread starter torrentsearcher

    (@torrentsearcher)

    Weet niemand een oplossing?

    Even samengevat:

    Je wil dat op de homepage (index.php) van alle posts een samenvatting wordt getoond. En dat in de categorie-pagina (category.php) alleen de titel en de datum wordt getoond (dus zonder samenvatting?).

    Dan pas je category.php aan. Vind the loop en zet daarin bijvorbeeld:

    <?php query_posts('cat=[vul hier het nummer van je categorie in]'); ?>
    <?php if (have_posts()) :  while (have_posts()) : the_post(); ?>
    
    <?php the_time('d-m-y'); ?> &raquo; <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> opgeslagen in de rubriek <?php the_category(', ') ?><br />
    
    <?php endwhile; else: ?>

    Je moet hierna nog een alternatieve loop hebben voor andere category’s. Dan zou je iets krijgen als cat=-3 in het stukje query_posts().

    Je zou dat dan ook weer in archive.php kunnen doen. Ik heb dit niet getest, maar het zou moeten werken. Bedoel je dit?

    Ik denk dat ik weet wat je zoekt, ik zoek het zelfde namelijk alleen dan met gewone pagina,s die een andere sidebar hebben.

    Kijk even of je hier wat aan hebt:
    gys-themed-categoriesphp.php (plaats in je pluginmap en activeer in de admin).

    Hiermee kan je een thema kiezen per (NIEUWE) Catogorie, hierbij de code van dat bestand, even opslaan als bovenstaande in notepad.

    <?php
    /*
    Plugin Name: GYS Themed Categories
    Plugin URI: http://get-your-stuff.com/
    Description: This plugin allows you to assign themes to each of your WordPress categories.  To assign themes to your categories, just go to Manage->Categories and you'll see a dropdown of all available themes at the bottom of the form. Get more GYS Themes and Plugins at <a href="http://get-your-stuff.com/">Get-Your-Stuff.Com</a>.
    Author: Mike Lopez
    Version: 2.1
    Author URI: http://mikelopez.info/
    */
    if(!class_exists('GYSThemedCategories')){
    	class GYSThemedCategories{
    		function GYSThemedCategories(){
    			$this->BlogCharset=get_option('blog_charset');
    			$this->OptionName=strtoupper(get_class($this));
    			$this->Options=get_option($this->OptionName);
    		}
    		function GetOption(){
    			$options=func_get_args();
    			$option=$this->Options;
    			foreach($options AS $o){
    				$option=$option[$o];
    			}
    			return $option;
    		}
    		function SetOptions(){
    			$options=func_get_args();
    			for($i=0;$i<count($options);$i+=2){
    				$this->Options[$options[$i]]=$options[$i+1];
    			}
    			update_option($this->OptionName,$this->Options);
    		}
    
    		// hooks
    
    		// CATEGORY FORM PROCESSING
    			function EditCategoryForm(){
    				$themes=get_themes();
    				$template=$this->GetOption('CategoryThemes',$_GET['cat_ID']);
    				$options='<option value="">---</option>';
    				foreach($themes AS $theme){
    					$selected=$theme['Template']==$template?' selected="true" ':'';
    					$options.='<option value="'.$theme['Template'].'"'.$selected.'>'.__($theme['Name']).' '.$theme['Version'].'</option>';
    				}
    				$form=<<<STRING
    				<div id="GYSThemedCategories">
    					<h3>GYS Themed Categories</h3>
    					<table class="form-table">
    						<tbody>
    							<tr class="form-field">
    								<th valign="top" scope="row">Category Theme</th>
    								<td><select name="GYSThemedCategories">{$options}</select></td>
    							</tr>
    						</tbody>
    					</table>
    				</div>
    				<script type="text/javascript">
    					//<![CDATA[
    					function GYSThemedCategories(){
    						try{
    							var x=document.getElementById('GYSThemedCategories');
    							var p=x.parentNode;
    							var t=p.getElementsByTagName('p')[0];
    							p.insertBefore(x,t);
    						}catch(e){}
    					}
    					GYSThemedCategories();
    					//]]>
    				</script>
    STRING;
    				echo $form;
    			}
    
    			function SaveCategory($id){
    				if(isset($_POST['GYSThemedCategories'])){
    					$catthemes=$this->GetOption('CategoryThemes');
    					if($_POST['GYSThemedCategories']){
    						$catthemes[$id]=$_POST['GYSThemedCategories'];
    					}else{
    						unset($catthemes[$id]);
    					}
    					$this->SetOptions('CategoryThemes',$catthemes);
    				}
    			}
    
    		// TEMPLATE PROCESSING
    			function Template($template){
    				$pid=$cid=0;
    				$perms=get_option('permalink_structure');
    				if($perms){
    					// get current URL if permalinks are set
    					$s=empty($_SERVER['HTTPS'])?'':$_SERVER['HTTPS']=='on'?'s':'';
    					$protocol='http'.$s;
    					$port=$_SERVER['SERVER_PORT']=='80'?'':':'.$_SERVER['SERVER_PORT'];
    					$url=$protocol.'://'.$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
    					list($url)=explode('?',$url);
    					// get Post ID from URL
    					$pid=url_to_postid($url);
    					// get Category ID from URL
    					list($url)=explode('/page/',$url); // <- added for paging compatibility
    					$cid=get_category_by_path($url,false);
    					$cid=$cid->cat_ID;
    				}else{
    					// no permalinks so we simply check GET vars
    					$pid=$_GET['p'];
    					$cid=$_GET['cat'];
    				}
    
    				if($pid){
    					// we're in a post page... so let's get the first category of this post
    					list($cat)=wp_get_post_categories($pid);
    				}elseif($cid){
    					// we're in a category page...
    					$cat=$cid;
    				}
    
    				if($cat){
    					// we have our category ID now so let's get the theme for it...
    					$theme=$this->GetOption('CategoryThemes',$cat);
    					// change template if a theme is specified for this category
    					if($theme)$template=$theme;
    				}
    
    				$this->Theme=$template;
    				return $template;
    			}
    
    			function Stylesheet(){
    				return $this->Theme;
    			}
    
    	}
    }
    if(class_exists('GYSThemedCategories') && !isset($GYSThemedCategories)){
    	$GYSThemedCategories=new GYSThemedCategories(__FILE__);
    }
    
    if(isset($GYSThemedCategories)){
    	add_action('edit_category_form',array(&$GYSThemedCategories,'EditCategoryForm'));
    	add_action('create_category',array(&$GYSThemedCategories,'SaveCategory'));
    	add_action('edit_category',array(&$GYSThemedCategories,'SaveCategory'));
    
    	add_filter('template',array(&$GYSThemedCategories,'Template'));
    	add_filter('stylesheet',array(&$GYSThemedCategories,'Stylesheet'));
    }
    ?>

    De Theme Webbutveckling heeft dit standaard erin zitten.

4 reacties aan het bekijken - 1 tot 4 (van in totaal 4)
  • Het onderwerp ‘Post theme aanpassen per categorie’ is gesloten voor nieuwe reacties.