Ik heb hieromtrent nog een vraag... Ik wil namelijk ook een selectie maken van categorieën die op de frontpage worden getoond.
Daarvoor heb ik de volgende plugins gevonden:
http://wordpress.org/extend/plugins/front-page-cats/
http://wordpress.org/extend/plugins/front-page-excluded-categories/
Beide plugins werken echter niet. Ik krijg geen foutmelding, maar er is eenvoudigweg geen resultaat te zien op mijn frontpage.
Bij de eerste plugin geef je aan welke moeten worden weergegeven. De code die ik hierbij gebruik:
[code]
<?php
/*
Plugin Name: Front Page Categories
Version: 0.3
Plugin URI: http://wordpress.org/#
Description: Select categories to display on the front page.
Author: Ryan Boren
*/
function fpc_where($where) {
// Change this to the categories you want to show on the front page.
// Example: $cats_to_show = '1 2 3 4';
$cats_to_show = '26';
global $wpdb, $wp_query;
if (! $wp_query->is_home) {
return $where;
}
$cat = $cats_to_show;
if (stristr($cat,'-')) {
// Note: if we have a negative, we ignore all the positives. It must
// always mean 'everything /except/ this one'. We should be able to do
// multiple negatives but we don't :-(
$eq = '!=';
$andor = 'AND';
$cat = explode('-',$cat);
$cat = intval($cat[1]);
} else {
$eq = '=';
$andor = 'OR';
}
$cat_array = explode(' ', $cat);
$whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]);
$whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' ');
for ($i = 1; $i < (count($cat_array)); $i = $i + 1) {
$whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]);
$whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' ');
}
$whichcat .= ')';
$where .= $whichcat;
return $where;
}
function fpc_join($join) {
global $wpdb, $wp_query;
if (! $wp_query->is_home) {
return $join;
}
$join .= " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) ";
return $join;
}
add_filter('posts_join', 'fpc_join');
add_filter('posts_where', 'fpc_where');
?>
[/code]
Er wordt na activatie niets weergegeven op mijn frontpage, terwijl categorie met ID 26 juist wél zou moeten verschijnen.
Bij de tweede plugin dien je juist aan te geven welke categorie níet getoond dient te worden. Code:
[code]
<?php
/*
Plugin Name: Front Page Excluded Categories
Version: 1.1.1
Plugin URI: http://geekularity.com/fp-excluded-categories-plugin-for-wordpress/
Description: This version uses a comma separated list of *excluded* category ids.
Author: Sean O'Steen
Author URI: http://geekularity.com/
*/
function fpe_where($where) {
// Change the $cats_to_exclude string to the category id you do not want to appear on the front page.
// Example: $cats_to_exclude = '1, 2, 3, 4';
$cats_to_exclude = '8';
global $wpdb, $wp_query;
if (! $wp_query->is_home || strlen($cats_to_exclude) == 0) {
return $where;
}
if (empty($wpdb->term_relationships))
{
$where .= " AND $wpdb->post2cat.category_id NOT IN (" . $cats_to_exclude . ")";
}
else
{
$where .= " AND $wpdb->term_taxonomy.term_id NOT IN (" . $cats_to_exclude . ")";
}
return $where;
}
function fpe_join($join) {
global $wpdb, $wp_query;
if (!$wp_query->is_home) {
return $join;
}
if (empty($wpdb->term_relationships))
{
$join .= " LEFT JOIN $wpdb->post2cat ON $wpdb->post2cat.post_id = $wpdb->posts.ID ";
}
else
{
if (!preg_match("/$wpdb->term_relationships/i",$join))
{
$join .=" LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) ";
}
if (!preg_match("/$wpdb->term_taxonomy/i",$join))
{
$join .=" LEFT JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id";
}
}
return $join;
}
function fpe_distinct($distinct) {
global $wp_query;
if (! $wp_query->is_home ) {
return $distinct;
}
return "distinct";
}
add_filter('posts_join', 'fpe_join');
add_filter('posts_where', 'fpe_where');
add_filter('posts_distinct', 'fpe_distinct');
?>
[/code]
Je raadt het al: hiermee blijven alle categorieën getoond.
Ik krijg sterk de indruk dat ik ergens iets verkeerd doe, maar heb geen idee wat. De bestanden heb ik, volgens mij naar aanraden in de readme's, in de root van de plugin directory geplaatst (en dus niet in een map in de plugin directory).
Iemand tips danwel betere plugins waar ik wél mee bereik wat ik wil?