Skip to:
Content
Pages
Categories
Search
Top
Bottom

Displaying Categories in Groups


  • phos flip
    Participant

    @wamoma

    I want to display categories in different groups. For example if I have groups called ‘Toys’ and ‘Pets’ and then have blog categories called ‘Toy News’ etc. I’d like to be able to choose (as the site admin) to have a tab in the ‘Toys Group’ displaying the latest posts from the ‘Toy News Categories’.

    I’m thinking this would have an admin screen that allows different categories to be linked to available groups, and if they are selected then they will appear in the relevant group.

    So far as I can see there is nothing that can do this already. I looked at groupblog but that’s a bit more involved than what I need.

    Therefore I’ll need to create a new plugin which will be a first! I’ve downloaded the skeleton component and a couple of others to try and take ideas from. I thought I’d post here because no doubt this is the sort of thing many of you could do in your sleep – if you are one of those talented people and could make any suggestions or point me in useful directions to get started I’d really appreciate it.

    No doubt I’ll have all sorts of more specific questions shortly, but if anyone has any advice please do let me know :)

Viewing 4 replies - 1 through 4 (of 4 total)

  • phos flip
    Participant

    @wamoma

    I’ve got stuck on this code:

    `if ( !groups_get_groupmeta( $bp->groups->current_group->id, ’14’ ) )

    {
    $this->enable_nav_item = true;
    } else {
    $this->enable_nav_item = false;
    }`

    I’m trying to insert the group ID or name. I’ve tried every variation I can think of but none work – it either displays in all groups or none whichever way I do it. Can somebody help with what I should be doing?


    Boone Gorges
    Keymaster

    @boonebgorges

    If you’re trying to check whether the group id is equal to 14, you’ll want something like this:
    `global $bp;
    if ( $bp->groups->current_group->id == 14 )
    `
    The groupmeta code you are currently using is looking for the existence of a piece of groupmeta with the meta_key ’14’. Is that what you mean to be doing?


    phos flip
    Participant

    @wamoma

    no that’s exactly what I was looking for – thanks :)


    phos flip
    Participant

    @wamoma

    Don’t know if this is any use to anyone and no doubt there are far better ways of doing it but just in case it is of use….

    I’ve created (hacked really) a plugin made up of 3 files, one of which is useless for now but at a future point I’d like to play around with it.

    bp-group-catdisp.php

    `<?php
    /*
    Plugin Name: Display Categories
    Plugin URI:
    Description: Displays a blog category in groups
    Author: Mas
    Version: 0.1
    License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
    Site Wide Only: true
    */
    if ( !defined( ‘BP_GROUP_CATDISP’ ) )
    define ( ‘BP_GROUP_CATDISP’, ‘programme’ );

    function bp_group_catdisp_init() {
    bp_group_catdisp_wrapper();
    }

    if ( defined( ‘BP_VERSION’ ) )
    bp_group_catdisp_wrapper();
    else
    add_action( ‘bp_init’, ‘bp_group_catdisp_init’ );
    //above links to admin screen in backend
    require(dirname(__FILE__) . “/bp-group-catdisp-admin.php”);

    // group options
    function bp_group_catdisp_wrapper() {
    class bp_group_catdisp extends BP_Group_Extension {
    var $visibility = ‘private’;

    var $enable_create_step = false;
    var $enable_edit_item = false;
    var $has_caps = false;

    function bp_group_catdisp () {
    global $groups_template;

    // group title

    $this->name = __( ‘Programme’, ‘programe’ );
    $this->slug = BP_GROUP_CATDISP;
    $this->nav_item_position = 12;
    $this->create_step_position = 12;

    // group ID for displaying category within
    global $bp;

    $group_array = array( 17,11 );

    if ( in_array( $bp->groups->current_group->id, $group_array) )
    //group ID to display in array. Note can reverse this code ie. set it not to display in listed groups by placing !in_array( $bp etc.

    {
    $this->enable_nav_item = true;
    } else {
    $this->enable_nav_item = false;
    }

    }

    function display () {
    global $bp, $groups_template;

    include(“bp-group-catdisp-edit.php”);

    //bit above links to file that prints to tab

    }

    }
    bp_register_group_extension( ‘bp_group_catdisp’ );
    }

    ?>
    `

    bp-group-catdisp-edit.php

    `

    stories4change Y-Care Programme

    Information and modules related to the Y-Care Programme 2010/11

    <a href="” rel=”bookmark” title=”Permanent Link to “>

    Sorry, no posts matched your criteria.

    `

    bp-group-catdisp-admin.php

    `<?php

    function group_catdisp_add_admin_menu() {
    add_submenu_page( ‘bp-general-settings’, __( ‘Group Categories’, ‘bp_group_catdisp’ ), __( ‘Disp Cats’, ‘bp_group_catdisp’ ), ‘manage_options’, __FILE__, ‘group_catdisp_plugin_options’ );
    }
    add_action(‘admin_menu’, ‘group_catdisp_add_admin_menu’, 15);

    function group_catdisp_plugin_options() {
    if (!current_user_can(‘manage_options’)) {
    wp_die( __(‘You do not have sufficient permissions to access this page.’) );
    }
    $updated = false;
    //above this is php for creating admin page and below is printed onto admin page

    ?>

    <?php
    if ( !$options = get_option( ‘bp_gm_settings’ ) )
    $per_page = 10;
    else
    $per_page = $options;

    $args = array( ‘type’ => ‘alphabetical’, ‘per_page’ => $per_page );

    if ( $_GET == ‘name’ )
    $args = ‘alphabetical’;
    else if ( $_GET == ‘group_id’ )
    $args = ‘newest’;
    else if ( $_GET == ‘popular’ )
    $args = ‘popular’;

    if ( $_GET )
    $args = $_GET;
    else
    $args = 1;

    if( bp_has_groups( $args ) ) :
    global $groups_template;
    ?>

    <?php
    if ( !$group )
    $group =& $groups_template->group;
    ?>

    Category

    Categories

    You don’t have any groups to manage.

    <?php
    }
    ?>
    `

    The first two hard code a group by ID and display a selected wordpress category within that group. The last file is the useless one. I’d started hacking from one of @boonebgorges plugins with the idea of creating an admin screen from which groups could be linked to blog categories.

    I’ve run out of time for now to play with that further and so for now am just going to duplicate the first two files for another couple of groups which will work for my purposes.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Displaying Categories in Groups’ is closed to new replies.
Skip to toolbar