Tengo la siguiente duda.
He creado una función para Worpress, (functions.php) ese es el código:
Código PHP:
<?php
function the_category_filter2($thelist,$separator=' ') {
if(!defined('WP_ADMIN')) {
//Category IDs to exclude
$categorias1 = range (1,5);
$categorias2 = range(13,1700);
$includee = array_merge($categorias1, $categorias2);
$includea = array();
foreach($includee as $d) {
$includea[] = get_cat_name($d);
}
$cats = explode($separator,$thelist);
$newlist = range();
foreach($cats as $cat) {
$catname = trim(strip_tags($cat));
if(!in_array($catname,$includea))
$newlist[] = $cat;
}
return implode($separator,$newlist);
} else {
return $thelist;
}
}
add_filter('the_categoryss', 'the_category_filter2', 10, 2);
?>
<?
function get_the_category_list3( $separator = '', $parents='', $post_id = false ) {
global $wp_rewrite;
$categories = get_the_category3( $post_id );
if ( !is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) )
return apply_filters( 'the_categoryss', '', $separator, $parents );
if ( empty( $categories ) )
return apply_filters( 'the_categoryss', __( 'Uncategorized' ), $separator, $parents );
$rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
$thelist = '';
if ( '' == $separator ) {
$thelist .= '<ul class="post-categories">';
foreach ( $categories as $category ) {
$thelist .= "\n\t<li>";
switch ( strtolower( $parents ) ) {
case 'multiple':
if ( $category->parent )
$thelist .= get_category_parents( $category->parent, true, $separator );
$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
break;
case 'single':
$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>';
if ( $category->parent )
$thelist .= get_category_parents( $category->parent, false, $separator );
$thelist .= $category->name.'</a></li>';
break;
case '':
default:
$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
}
}
$thelist .= '</ul>';
} else {
$i = 0;
foreach ( $categories as $category ) {
if ( 0 < $i )
$thelist .= $separator;
switch ( strtolower( $parents ) ) {
case 'multiple':
if ( $category->parent )
$thelist .= get_category_parents( $category->parent, true, $separator );
$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>';
break;
case 'single':
$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>';
if ( $category->parent )
$thelist .= get_category_parents( $category->parent, false, $separator );
$thelist .= "$category->name</a>";
break;
case '':
default:
$thelist .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>';
}
++$i;
}
}
return apply_filters( 'the_categoryss', $thelist, $separator, $parents );
}
?>
<?
function get_the_terms3( $id = 0, $taxonomy ) {
global $post;
$id = (int) $id;
if ( !$id ) {
if ( !$post->ID )
return false;
else
$id = (int) $post->ID;
}
$args = array('orderby' => 'ID');
$terms = wp_get_object_terms( $id, $taxonomy, $args);
if ( false === $terms ) {
$args = array('orderby' => 'ID');
$terms = wp_get_object_terms( $id, $taxonomy, $args);
wp_cache_add($id, $terms, $args, $taxonomy . '_relationships');
}
$terms = apply_filters( 'get_the_terms3', $terms, $id, $taxonomy, $args );
if ( empty( $terms ) )
return false;
return $terms;
}
?>
<?php
function get_the_category3( $id = false ) {
$categories = get_the_terms3( $id, 'category' );
if ( ! $categories )
$categories = array();
$categories = array_values( $categories );
foreach ( array_keys( $categories ) as $key ) {
_make_cat_compat( $categories[$key] );
}
// Filter name is plural because we return alot of categories (possibly more than #13237) not just one
return apply_filters( 'get_the_categories', $categories );
}
?>
<?
function the_categoryss( $separator = '', $parents='', $post_id = false ) {
echo get_the_category_list3( $separator, $parents, $post_id );
}
?>
Código PHP:
<?php the_categoryss(' - ')?>
Sin embargo me gustaria capturar el resultado de dicha funcion en una variable.
Lo he realizado de la siguiente manera:
<?php $categorias =the_categoryss(' - ') ?>
Si embargo la variable esta vacia.
¿Como podria solucionarlo.
Un saludo.