GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Webmaster Q & Fuckin' A (https://gfy.com/forumdisplay.php?f=27)
-   -   Adding 2nd WP Custom Taxonomy? (https://gfy.com/showthread.php?t=1113879)

Tittytweaker 06-28-2013 11:40 AM

Adding 2nd WP Custom Taxonomy?
 
I'm a bit confused. I've added a custom taxonomy called "models", and now I'm trying to add a new one, but when I do that I get this:

Fatal error: Cannot redeclare add_custom_taxonomies() (previously declared in /home/content/42/10173742/html/wp-content/themes/adultphoto-01-pink/functions.php:139) in /home/content/42/10173742/html/wp-content/themes/adultphoto-01-pink/functions.php on line 198

I'm sure this has to do with my lack of knowledge regarding PHP, I'm probably doing something wrong when I try to add it. Here is the code from my theme functions page as it is now:
Code:

<?php

//Short titles for preview link

function short_title($after = '', $length) {
    $mytitle = get_the_title();
    if ( strlen($mytitle) > $length ) {
    $mytitle = substr($mytitle,0,$length);
    echo rtrim($mytitle).$after;
    } else {
    echo $mytitle;
    }
}

//Removing useless CSS that WP pasts right inside BODY tags... (?)

function remove_gallery_css( $css ) {
    return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
}

add_filter( 'gallery_style', 'remove_gallery_css' );

//Post thumbsnails support

if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails' );
}

//Left sidebar

if ( function_exists('register_sidebar') ) {
    register_sidebar(array(
        'name' => 'Left Sidebar',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h3>',
        'after_title' => '</h3>'));
}

//Right sidebar

if ( function_exists('register_sidebar') ) {
    register_sidebar(array(
        'name' => 'Right Sidebar',
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h3>',
        'after_title' => '</h3>'));
}

//Main menu

add_action( 'init', 'register_my_menus' );

function register_my_menus() {
    register_nav_menus(
        array( 'header-menu' => __( 'Header Menu' ))
  );
}

//Thanks to http://design.sparklette.net/teaches/how-to-add-wordpress-pagination-without-a-plugin/ for pagination function

function pagination($pages = '', $range = 9)
{
    $showitems = ($range * 2)+1;
 
    global $paged;
    if(empty($paged)) $paged = 1;
 
    if($pages == '')
    {
        global $wp_query;
        $pages = $wp_query->max_num_pages;
        if(!$pages)
        {
            $pages = 1;
        }
    } 
 
    if(1 != $pages)
    {
        echo "<span>Page ".$paged." of ".$pages."</span>";
        if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
        if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
 
        for ($i=1; $i <= $pages; $i++)
        {
            if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
            {
                echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
            }
        }
 
        if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
        if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
       
    }
}

//Cumstom comments template

function custom_comments($comment, $args, $depth) {
   
    $GLOBALS['comment'] = $comment; ?>
   
    <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
                   
        <?php echo get_avatar( $comment, 64 ); ?>
                       
        <span class="comment-author"><?php comment_author_link() ?> says:
                       
        <?php if ($comment->comment_approved == '0') : ?>
                       
        <em>(!) your comment is awaiting moderation</em>
                       
        <?php endif; ?>
                       
        </span>

        <small class="comment-data"><a href="#comment-<?php comment_ID() ?>" title="Permanent link to this comment"><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a><?php edit_comment_link('Edit', ' | ', ''); ?></small>
                       
        <?php comment_text() ?>
                       
        <div class="clear"></div>

        </li>
   
    <?php
   
    }
/**
 * Add custom taxonomies
 *
 * Additional custom taxonomies can be defined here
 * http://codex.wordpress.org/Function_Reference/register_taxonomy
 */
function add_custom_taxonomies() {
        // Add new "Model" taxonomy to Posts
        register_taxonomy('model', 'post', array(
                // Hierarchical taxonomy (like categories)
                'hierarchical' => false,
                // This array of options controls the labels displayed in the WordPress Admin UI
                'labels' => array(
                        'name' => _x( 'Model', 'taxonomy general name' ),
                        'singular_name' => _x( 'Model', 'taxonomy singular name' ),
                        'search_items' =>  __( 'Search Model' ),
                        'all_items' => __( 'All Model' ),
                        'parent_item' => __( 'Parent Model' ),
                        'parent_item_colon' => __( 'Parent Model:' ),
                        'edit_item' => __( 'Edit Model' ),
                        'update_item' => __( 'Update Model' ),
                        'add_new_item' => __( 'Add New Model' ),
                        'new_item_name' => __( 'New Model Name' ),
                        'menu_name' => __( 'Model' ),
                ),
                // Control the slugs used for this taxonomy
                'rewrite' => array(
                        'slug' => 'model', // This controls the base slug that will display before each term
                        'with_front' => false, // Don't display the category base before "/model/"
                        'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
                ),
        ));
}
add_action( 'init', 'add_custom_taxonomies', 0 );

?>

I'm trying to add a taxonomy called "Site", and I'm basically just copying and pasting the same chunk of taxonomy code and changing everything to "site" instead of "model". Can anyone tell me what's happening / what I need to do?

alcstrategy 06-28-2013 11:53 AM

Quote:

Originally Posted by Tittytweaker (Post 19691039)
I'm a bit confused. I've added a custom taxonomy called "models", and now I'm trying to add a new one, but when I do that I get this:

Fatal error: Cannot redeclare add_custom_taxonomies() (previously declared in /home/content/42/10173742/html/wp-content/themes/adultphoto-01-pink/functions.php:139) in /home/content/42/10173742/html/wp-content/themes/adultphoto-01-pink/functions.php on line 198

I'm sure this has to do with my lack of knowledge regarding PHP, I'm probably doing something wrong when I try to add it. Here is the code from my theme functions page as it is now:
Code:

<?php

/**
 * Add custom taxonomies
 *
 * Additional custom taxonomies can be defined here
 * http://codex.wordpress.org/Function_Reference/register_taxonomy
 */
function add_custom_taxonomies() {
        // Add new "Model" taxonomy to Posts
        register_taxonomy('model', 'post', array(
                // Hierarchical taxonomy (like categories)
                'hierarchical' => false,
                // This array of options controls the labels displayed in the WordPress Admin UI
                'labels' => array(
                        'name' => _x( 'Model', 'taxonomy general name' ),
                        'singular_name' => _x( 'Model', 'taxonomy singular name' ),
                        'search_items' =>  __( 'Search Model' ),
                        'all_items' => __( 'All Model' ),
                        'parent_item' => __( 'Parent Model' ),
                        'parent_item_colon' => __( 'Parent Model:' ),
                        'edit_item' => __( 'Edit Model' ),
                        'update_item' => __( 'Update Model' ),
                        'add_new_item' => __( 'Add New Model' ),
                        'new_item_name' => __( 'New Model Name' ),
                        'menu_name' => __( 'Model' ),
                ),
                // Control the slugs used for this taxonomy
                'rewrite' => array(
                        'slug' => 'model', // This controls the base slug that will display before each term
                        'with_front' => false, // Don't display the category base before "/model/"
                        'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
                ),
        ));
}

?>

I'm trying to add a taxonomy called "Site", and I'm basically just copying and pasting the same chunk of taxonomy code and changing everything to "site" instead of "model". Can anyone tell me what's happening / what I need to do?

dump the function declaration above because ut's already declared elsewhere so it is ready for you to use. There is no need for you to define the function again.


at second look just use register_taxonomy without wrapping it in a function to do what you want

do you have skype i will explain to you easier

Tittytweaker 06-28-2013 12:18 PM

I don't have skype, it's easier for me to just do it in here anyway since I can come back to it whenever it is convenient for me.

I think I get what you are saying though. However since I'm not familiar with PHP, I don't know where exactly I'm going to be putting the code, or even what the necessary chunk of code is. Can you show me exactly what part of the code needs to be copied and where it goes?

alcstrategy 06-28-2013 12:25 PM

i really dont know the full picture but I guess you could do a couple things

I suppose you could go to the other function declaration you did to add taxonomy and just register the model taxonomy in that one

or if you want to just keep what you have for simplicity or whatever

rename this add_custom_taxonomies to addModelTaxonomy()

then use addModelTaxonomy in your init

add_action( 'init', 'addModelTaxonomy');

i suppose its a workaround way but might be simplest for you I don't really want to get too deep into this

Tittytweaker 06-28-2013 02:20 PM

Well, the model taxonomy is the one I have already added, the one that functions. I'm just trying to add a new one. Again, I'm entirely unfamiliar with PHP, so I'd have to actually see the final / correct code in order to understand.

spankalot 06-28-2013 05:59 PM

Simply add following code to your functions.php in theme folder:

Code:

function some_custom_taxonomy_init() {
        // create a new taxonomy
        register_taxonomy(
                '<put_your_taxonomy_name_here>',
                'post',
                array(
                        'label' => __( 'People' ),
                        'rewrite' => array( 'slug' => '<put_your_taxonomy_slug_here>' ),
                        'capabilities' => array(
                                'assign_terms' => 'edit_guides',
                                'edit_terms' => 'publish_guides'
                        )
                )
        );
}
add_action( 'init', 'some_custom_taxonomy_init' );

<put_your_taxonomy_name_here> - change this (this will be the name of custom taxonomy)

<put_your_taxonomy_slug_here> - change this (this will be displayed in link domain.com/this_taxonomy/)

note: this taxonomy will be added to default post type (Post)

name of the functions must be unique, now is "some_custom_taxonomy_init"

Tittytweaker 06-29-2013 08:32 AM

Thanks for the clarification. I get what you mean. I'm now able to add that taxonomy, however, now I get this error at the top of my screen:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/42/10173742/html/wp-content/themes/adultphoto-01-pink/functions.php:168) in /home/content/42/10173742/html/wp-content/plugins/easy-batch-uploader-0.4.0/class-main.php on line 135

It's interfering with a custom plugin. I e-mailed the guy who made it, still waiting for a reply - but figured I'd mention it here too.

Do you guys think this is a problem with the taxonomy I made, or with the plugin? Considering my other custom taxonomy didn't interfere with the plugin, I'm thinking I'm still doing something wrong with the new one.

This is the code that I have added:

Code:

<?php
   
   
/**
 * Add custom taxonomies
 *
 * Additional custom taxonomies can be defined here
 * http://codex.wordpress.org/Function_Reference/register_taxonomy
 */
function add_custom_taxonomies_site_init() {
        // Add new "Site" taxonomy to Posts
        register_taxonomy('Site', 'post', array(
                // Hierarchical taxonomy (like categories)
                'hierarchical' => false,
                // This array of options controls the labels displayed in the WordPress Admin UI
                'labels' => array(
                        'name' => _x( 'Site', 'taxonomy general name' ),
                        'singular_name' => _x( 'Site', 'taxonomy singular name' ),
                        'search_items' =>  __( 'Search Site' ),
                        'all_items' => __( 'All Site' ),
                        'parent_item' => __( 'Parent Site' ),
                        'parent_item_colon' => __( 'Parent Site:' ),
                        'edit_item' => __( 'Edit Model' ),
                        'update_item' => __( 'Update Site' ),
                        'add_new_item' => __( 'Add New Site' ),
                        'new_item_name' => __( 'New Site Name' ),
                        'menu_name' => __( 'Site' ),
                ),
                // Control the slugs used for this taxonomy
                'rewrite' => array(
                        'slug' => 'site', // This controls the base slug that will display before each term
                        'with_front' => false, // Don't display the category base before "/model/"
                        'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
                ),
        ));
}
add_action( 'init', 'add_custom_taxonomies_site_init', 0 );

?>


spankalot 06-29-2013 11:09 AM

There's nothing wrong with the taxonomy. The error means that you have printed something out before the headers were sent meaning that there's some kind of print/echo command in your functions.php file... check the error code lines.

Tittytweaker 06-29-2013 01:07 PM

I manged to fix it by combining the two custom taxonomy chunks into one chunk of php code, I think. Basically took out the closing tags of the first one, and the opening tags of the second. Corresponded to the line error, so I guess that was it.

Now I'm getting an error when I try to use get_the_term_list to display the taxonomy on a page. :

Catchable fatal error: Object of class WP_Error could not be converted to string in /home/content/42/10173742/html/wp-content/themes/adultphoto-01-pink/single.php on line 45

The code is:

Code:

<div class="image-site"><?php

$site_list = get_the_term_list( $post->ID, 'site', 'Site: ', ', ', '' );

// Output taxonomy information if there was any

if ( '' != $site_list ) {
echo $site_list;
} // endif

?>
</div>

Line 45 is echo $site_list;. This is the same code I'm using to display the other taxonomy on the page as well, just a different term. Each are in a separate div so I don't think I can fix it the same way I did with the other. Ideas?

Thanks for being patient with me, this php stuff is just way over my head, difficult to grasp.

Tittytweaker 06-30-2013 08:55 AM

Bump. Anyone?

Tittytweaker 07-01-2013 09:09 AM

Anyone? Still getting this error. I also can't view the results for that archive page. If I go to a term that I know has posts in it, it still says there were no results.

Tittytweaker 07-02-2013 09:14 AM

Figured it all out. For anyone who finds this post who has similar problems, find an auto taxonomy code generator, just so you can be sure you aren't messing anything up yourself. Then refresh the permalink structure. That fixed everything for me. Such an easy fix, just had to find it.


All times are GMT -7. The time now is 06:03 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123