that FI-DD wrote (enables to show certain posts that a certain x-field
is =, >, < etc' of something you decide), very useful one, as I wanted
to use it in my site too, but I needed to show two different includes with it,
but there seems to be a problem when you use xfieldfilter in two includes in the
same page! it will error immediatly, so I made a way to fix that, here is that fix:
in show.news.php find the xfield-filter code:
- Code: Select all
if(isset($xfieldfilter)){
function xfield_filter($id){
global $xfieldfilter;
$return = true;
$path_to_xfields = 'cms/data/xfields-data.txt';
$xfield_data = file($path_to_xfields);
foreach($xfield_data as $line){
$line_arr = explode("|>|", $line);
if($line_arr[0] == $id){
$all_xfields = explode("||", $line_arr[1]);
foreach($all_xfields as $single_xfield){
$my_xfield = explode("|", $single_xfield);
if($my_xfield[0] == $xfieldfilter[0]){
if($xfieldfilter[1] == '='){
if(trim($my_xfield[1]) == $xfieldfilter[2]){
$return = false;
}
}
if($xfieldfilter[1] == '<'){
if(trim($my_xfield[1]) < $xfieldfilter[2]){
$return = false;
}
}
if($xfieldfilter[1] == '>'){
if(trim($my_xfield[1]) > $xfieldfilter[2]){
$return = false;
}
}
if($xfieldfilter[1] == '<='){
if(trim($my_xfield[1]) <= $xfieldfilter[2]){
$return = false;
}
}
if($xfieldfilter[1] == '>='){
if(trim($my_xfield[1]) >= $xfieldfilter[2]){
$return = false;
}
}
}
else{
continue;
}
}
}
else{
continue;
}
}
return $return;
}
}
And change it to:
- Code: Select all
if($twoxf != 'true'){
if(isset($xfieldfilter)){
function xfield_filter($id){
global $xfieldfilter;
$return = true;
$path_to_xfields = 'cms/data/xfields-data.txt';
$xfield_data = file($path_to_xfields);
foreach($xfield_data as $line){
$line_arr = explode("|>|", $line);
if($line_arr[0] == $id){
$all_xfields = explode("||", $line_arr[1]);
foreach($all_xfields as $single_xfield){
$my_xfield = explode("|", $single_xfield);
if($my_xfield[0] == $xfieldfilter[0]){
if($xfieldfilter[1] == '='){
if(trim($my_xfield[1]) == $xfieldfilter[2]){
$return = false;
}
}
if($xfieldfilter[1] == '<'){
if(trim($my_xfield[1]) < $xfieldfilter[2]){
$return = false;
}
}
if($xfieldfilter[1] == '>'){
if(trim($my_xfield[1]) > $xfieldfilter[2]){
$return = false;
}
}
if($xfieldfilter[1] == '<='){
if(trim($my_xfield[1]) <= $xfieldfilter[2]){
$return = false;
}
}
if($xfieldfilter[1] == '>='){
if(trim($my_xfield[1]) >= $xfieldfilter[2]){
$return = false;
}
}
}
else{
continue;
}
}
}
else{
continue;
}
}
return $return;
}
}
}
That will add a variable that you put in the 2nd include, like this:
$twoxf = 'true';
Thats it, now you will be able to have two includes that both use
the xfield filter.
But! there is another small "bug" I'de like you to help me with, when you
filter news by xfield, it will show you exactly the news you want - but!
when you use $number = X; it will not always show you the right amount
because it counts the number of posts by the posts in the categories you chose only!
example:
10 news in cat 1
news 1, 3 and 7 has the xfield you looked for
$number = 3;
it will only show you the first two suitable posts
as it will search only in the 3 first posts of the category and will
not try to continue looking until it finds 3!
Well, I tried several ideas I had to fix that, still no luck
Hope my fix helps someone and if you have an idea on
how to make it show the real amount of posts I'de be glad!
