inside categories id’s 4,5,6. I’m put this id’s in my theme options. imp_cat thats a options textfield id. In this textfield I put categories ID’s -4,5,6. Before this in all other cases all works is fine but this code isn’t work.
You’re not feeding it an array though, you’re placing a string into an array (the array only has one item).
// Example var holding text field value
$imp_cat = '1,2,3';
// This array only has one value, the data in the string above
$some_array = array( $imp_cat );
// This would also be the same as above
$some_array = array('1,2,3');
// The array only has one item, a string with 3 numbers and commas
If you want to take a string and split it into an array of items, then you should use something like explode on the string to divide it into an array.
http://php.net/manual/en/function.explode.php
$var = get_option('option_with_string_of_ids');
// The first parameter is the delimter to find in the string and divide the items by (it removes the delimeter in the process)
$var = explode( ',' , $var );
/*
$var is now an array
Array(
0 => ID1,
1 => ID2
)
..and so on..
*/
I’ll try to make this. This isn’t work.
add_filter( 'single_template', 'my_template' );
function my_template( $template ) {
$catid = get_option('imp_cat');
if ( in_category(array($catid)) )
$template = locate_template( array( 'single-port.php' ) );
return $template;
}
I dont understand about explode and how to get this work with my function.
After this..
$catid = get_option('imp_cat');
Add..
$catid = strpos( $catid , ',' ) ? explode( ',' , $catid ) : array( (int) $catid );
And change this..
if ( in_category(array($catid)) )
..for..
if ( in_category( $catid ) )
Refs:
http://codex.wordpress.org/Function_Reference/in_category
http://php.net/manual/en/function.strpos.php
http://php.net/manual/en/function.explode.php
Man THANK YOU VERY MUCH. You’re a good man. Thanks for this help.
Sorry for insolence, maybe you can explaine how to resolve This problem.
Past few week trying to resolve this problem.