模板包演练 - 简单级别

模板包演练 - 简单级别

Codex Home → Legacy Docs → Archived Section: Theme Development → Themes & the BuddyPress Template Pack → Template Pack Walkthrough – Easy Level
Template Pack Walkthrough – Easy Level

Archived file. Good only up to BP 1.6.5 version

BP TEMPLATE PACK 1.0.2 with MOTION THEME 1.0.7 on WORDPRESS 3.0.1 and BUDDYPRESS 1.2.5.2
After moving the BP Template Pack component folders into your active WordPress theme in Step 1 and getting a success message in Step 2 regarding the transfer, you will proceed to Step 3 where you』ll be asked to check if the HTML structure is aligned. To illustrate this step, we will be using the 2-column Motion Theme which is available for download at the WordPress Themes repository.
Motion Theme
Going Through the BP Template Pack Compatibility Process
Activating the BP Template Pack plugin and going through the first two steps of the process do not affect the layout of the regular pages as seen below except to add the BP Admin Bar positioned above the body of the theme.

Going to the site』s activity page (http://yoursite.com/activity/) however, you』ll find that some elements of the BuddyPress components need to be tweaked.

We need to compare the template structures of the Motion Theme with the BP templates which have been transferred to the folder of your active theme and transpose the HTML structure of the Motion Theme onto the 13 Template Pack files. (Note: 16 template files as of BP 1.5)
BP templates use this HTML structure by default:
[HEADER]

[PAGE CONTENT]

[FOOTER]

Full Width and/or 2-Column Layout for BP Components
Per instructions in Step 3, you should look at the page.php or the index.php file of your active WP theme and copy the HTML structure there onto the 13 BP template files (Note: 16 template files as of BP 1.5).
The Motion theme has a full width structure (no sidebar) instead of a 2-column layout in its page.php and a 2-column layout in its index.php. We』ll be covering both layouts.
A. Full Width Layout
This is the HTML structure of Motion Theme』s page.php
[HEADER]

[PAGE CONTENT]


[FOOTER]

If you choose to have full width pages for your BuddyPress components, starting with the activity/index.php file which is now in your Motion Theme』s folder you will need to replace

with

Then at the bottom part of activity/index.php, replace

with

After which, you then make the same revisions in the remaining template files as indicated in the instructions in Step 3 of the process.
Note: list below has been updated to show the 16 template files which need to be revised.

/activity/index.php – DONE above
/blogs/create.php
/blogs/index.php
/forums/index.php
/groups/index.php
/groups/create.php
/groups/single/home.php
/groups/single/plugins.php
/members/index.php
/members/single/home.php
/members/single/plugins.php
/members/single/settings/delete-account.php
/members/single/settings/general.php
/members/single/settings/notifications.php
/registration/activate.php
/registration/register.php

B. 2-Column Layout
If you prefer to have a 2-column layout for your BP component pages, open up Motion theme』s index.php file and you』ll see the HTML structure like so:
[HEADER]

[PAGE CONTENT]

[FOOTER]

The template file structure of Motion Theme』s 2-column layout is the same as the default BP Template Pack』s files』. You only need to modify the name of the container div from id=」container」 to id=」main」. Replace

with

starting with the activity/index.php then apply revision to the remaining BP template files which need to be revised per list.
An Alternative Way to Implement the 2-column Layout
Fortunately, the Motion theme does not have #container div in any of its template files – checked in style.css and double-checked in header.php. So instead of going through the tedious process of changing the container div from #container to #main in the 13 BP template files (Note: 16 template files as of BP 1.5), it would be much easier to tweak the layout in all aforementioned files by making one change in Motion theme』s style.css.
Add the #container div selector in Motion theme』s style.css file. Change this
#main {
padding: 30px 0 20px 0;
}

to this
#main, #container {
padding: 30px 0 20px 0;
}

That was easy. Using this method, you won』t need to make revisions to 13 template files (Note: 16 template files in BP 1.5) each time the BP Template Pack plugin is updated.
Using Different Layouts for Different Components
Now that you know the HTML structures of Motion theme templates for full width and 2-columns layouts, you have the option to apply full widths to certain BP components and 2-columns for the others. The images below show a member』s activity page with a 2-column format and with a full width format (click on images to enlarge). Your choice.
After you implement the layout/s you preferred for the BP Components in the BP template files, you』re ready to go to the final steps of the process.
Final Steps
A. Add BuddyPress Tag to Motion Theme』s style.css
/*
Theme Name: Motion
...
...
Tags: buddypress, black, blue, green, dark, two-columns, sticky-post, threaded-comments, fixed-width, right-sidebar
...
...
*/

B. Add BP Component Navigation Links
You can add the navigation links for the BuddyPress Components you have enabled for your site in at least three different areas in Motion Theme』s header.php file.
1. Add BP navigation links to div#topmenu in header.php

The result:

2. Replace Category Links in div#catnav

The result:

3. Add a New div Above div#catnav

And use the styling of #catnav in this new div#newbplinks
/************************************************
* New BP Component-specific Links Div *
************************************************/
#newbplinks {
overflow: hidden;
width: 980px;
background: url(images/blacktrans.png);
}

#newbp li {
float: left;
background: url(images/blacktrans.png);
line-height: 2em;
margin: 5px 0 5px 5px;
}
#newbp li:hover {
background: url(images/blacktrans2.png);
}
#newbp li a {
display: block;
margin: 0;
font-size: 0.8em;
color: #fff;
padding: 0 13px;
}
#newbp li a:hover {
color: #afdaff;
text-decoration: none;
display: block;
}
#newbp li ul {
position: absolute;
width: 180px;
left: -999em;
padding-top: 5px;
margin: 0;
}
#newbp li:hover ul,#newbp li.sfhover ul {
left: auto;
}
#newbp li li {
padding: 0;
margin: 0;
width: 180px;
line-height: 1.5em;
}
#newbp li li a {
color: #fff;
margin: 0;
padding: 7px 13px;
background: url(images/blacktrans3.png);
}
#newbp li li ul li {
margin-left: 13px;
}
#newbp li li a:hover {
color: #afdaff;
}
#newbp li:hover,#newbp li.sfhover {
position:static; /* prevents IE7 drop-down menu bug where focus on a page element prevents nested menus from disappearing */
}

The result:

C. Style Elements of BP Component
At this stage, we need to make a few more tweaks to some elements so that the integration of BP components can be completed.
1. Disable BP Template Pack CSS
In the final steps check 「Disable BP Template Pack CSS」 and click on the 「Save Settings」 link. Copy bp.css included in Template Pack and paste at the bottom of Motion Theme』s style.css file.
Change the path of adminbar.css you copied and move it along with the line above it up to right under the stylesheet header.
From
@import url( ../buddypress/bp-themes/bp-default/_inc/css/adminbar.css );

to
@import url( ../../plugins/buddypress/bp-themes/bp-default/_inc/css/adminbar.css );

Move lines to under style.css header
/*
Theme Name: Motion
...
...
Tags: buddypress, black, blue, green, dark, two-columns, sticky-post, threaded-comments, fixed-width, right-sidebar
...
...
*/

/* Load the default admin bar styles */
@import url( ../../plugins/buddypress/bp-themes/bp-default/_inc/css/adminbar.css );

2. Component-specific Styling Tweaks
While some styles from bp.css cover the general layout of the elements within the different components, some additional tweaks are recommended. Some examples:

For this particular theme, you can add this at the bottom of your theme』s style.css to correct font-sizes, alignments, etc.
/************************************************
* Theme-Specific CSS Tweaks *
************************************************/

div.item-list-tabs,
ul.activity-list,
ul.item-list,
div#whats-new-options,
form.dir-form div.dir-search,
div.pag-count,
div.info,
form#forum-topic-form label,
form#forum-topic-form select,
form#forum-topic-form div.submit,
form.standard-form textarea,
div#item-header div#item-header-content,
div#topic-meta a,
form.standard-form input[type="text"] {
font-size: 0.8em;
line-height:1.5em;
}

div#item-header-content h2 a {
font-size: 1.5em;
line-height: 1em;
}

form.dir-form div.dir-search {
margin-top: -20px;
width: auto;
}

form#forum-topic-form {
margin-top: 20px;
}

form.standard-form textarea,
form.standard-form input[type="text"] {
width: 100%;
}

div#item-header div#item-actions {
float:right;
margin:0 0 15px 15px;
text-align:right;
width:20%;
}

div#item-header div#item-actions h3 {
font-size: 0.8em;
line-height: 1em;
margin:0 0 5px;
}

div#topic-meta h3,
div#post-topic-reply h4 {
padding: 15px 0px;
}

div.poster-meta img.avatar {
float: left;
margin: 0px 7px 7px 0px;
}

div.item-list-tabs ul li {
margin-right: 0px;
}

div.item-list-tabs ul li a {
display: block;
padding: 5px 10px 3px 0px;;
text-decoration: none;
}

table.forum {
font-size: 0.75em;
line-height: 1.4em;
width: 100%;
}

table.forum a img.avatar,
table.forum div.poster-name {
float: left;
margin-right: 5px;
}

form#whats-new-form #whats-new-textarea {
margin-top: 10px;
}

div.dir-search label {
display: inline;
}

ul#groups-list li,
ul#members-list li,
ul#blogs-list li,
ul#topic-post-list li {
margin-bottom: 15px;
}

Adjust above styling to taste.

安装向导 (v1.5)

安装向导 (v1.5)

Codex Home → Legacy Docs → Archived Section: Getting Started → Installation Wizard (v1.5)
Installation Wizard (v1.5)

Archived file. Good only up to BP 1.5 version

After installing and activating BuddyPress, you will see an admin message with the link to the new BuddyPress Installation Wizard. Click on the "installation wizard" link.

Step 1: Choose the BuddyPress Components you want in your installation.
Click on "Save & Next" button.

Step 2: Associate/Create Pages for your BuddyPress Components.
Click on "Save & Next" button.

Step 3: Choose Pretty Permalinks structure.
Click on "Save & Next" button.

Step 4: Choose theme to use for your BP install.
Recommend using the bp-default theme to test drive all the BP features you activated. Click on "Save & Next" button.

Step 5: Finish and Activate

You now have the following tables in your database

Proceed to Next Task
Configure BuddyPress Components for BP 1.5

Deleting BuddyPress

Deleting BuddyPress

Codex Home → Getting Started → Deleting BuddyPress
Deleting BuddyPress

So you』ve decided to stop using BuddyPress. That』s too bad. If something went wrong during your installation or if you ran into its 「limitations」 make sure to check out:
– The Support Forum for help
– The Plugin Directory for awesome BuddyPress plugins.
If you still want to stop using BuddyPress you can just follow these steps below.
Step 1: Disable all BuddyPress related plugins.
It』s a good idea to start with disabling and removing all the plugins on your site which need BuddyPress to function. Certain older plugins might give you a blank page when being active without BuddyPress being enabled. Go to your admin panel and visit the Plugins page. Disable all the plugins related to BuddyPress.

Step 2: Disable BuddyPress and delete the plugin files.
Once again go to your Plugin page and disable BuddyPress the same way as you disable the BuddyPress related plugins. Click the 「disable」 button and you now have disabled BuddyPress.

If you encounter a white page after disabling BuddyPress take a close look at your plugins. Are you sure none of them need BuddyPress to function? If you』re sure that no BuddyPress related plugins are active check if the currently active Theme is not a BuddyPress Theme. If you do have a BuddyPress Theme as your active theme, rename or delete the theme from your Theme folder, so that WordPress resets to the default theme.
Finally you can remove the BuddyPress files by clicking on the 「delete」 button on the plugin page.
You have now successfully removed BuddyPress!
Advanced Optional Step: Removing the database tables
Warning: Make sure to backup your database first! Making a mistake during this process can result in a broken or entirely removed database! If you are not comfortable using PHPMyAdmin do not even go here. Mistakes are made fast so be careful! A guide to backing up a WP DB can be found here: codex.wordpress.org/Backing_Up_Your_Database
Open up PHPMyAdmin through your webhosting panel (cPanel, Plesk or any other system) and visit your WordPress database. Select all the database tables that have WP_BP_ as prefix. If you have chosen a different table prefix during your WordPress installation they can be named differently. The structure is always like this: [table prefix]_BP_
If you have BuddyPress dependent plugins installed you might want to scan your database for any additional unneeded tables, but make sure you』re not dropping a table which is needed for a plugin to function!

When you』ve selected all these tables use the dropdown at the bottom of the page and select 「Drop Tables」 and press the 「Go」 button.

BuddyPress is now completely removed including its database tables.
Advanced Optional Step: Removing BuddyPress』 options from the wp_options table
Warning: Make sure to backup your database first! Making a mistake during this process can result in a broken or entirely removed database! If you are not comfortable using PHPMyAdmin do not even go here. Mistakes are made fast so be careful! A guide to backing up a WP DB can be found here: codex.wordpress.org/Backing_Up_Your_Database
N.B. An additional step that you might like to take if editing tables and working in phpMyAdmin is to use it』s ability to make a full copy of an existing DB under a new name, doing this allows you to simply switch your wp-config DB entry to point to the copied DB for a quick recovery should things go wrong; you are, however, still advised to take a sql backup dump as well for total peace of mind.
Open up PHPMyAdmin through your webhosting panel (cPanel, Plesk or any other system) and visit your WordPress database.
Navigate to the WordPress options table. (By default, this is the 「wp_options」 table, but might be different if you changed your database prefix.)
Next, find the following entries under the option_name column:

bp-db-version (for BuddyPress 1.5)
_bp_db_version (as of BuddyPress 1.6)
bp-active-components
bp-blogs-first-install
bp-deactivated-components
bp-disable-account-deletion
bp-disable-avatar-uploads
bp-disable-blogforum-coments
bp-disable-profile-sync
bp-pages
bp-xprofile-base-group-name
bp-xprofile-fullname-field-name

And delete them from the database.

使用内置的 WordPress 菜单

使用内置的 WordPress 菜单

Codex Home → Legacy Docs → Archived Section: Getting Started → Using the Built-in WordPress Menus
Using the Built-in WordPress Menus

The latest BuddyPress 1.5 default theme now includes the standard WordPress menus that you can easily set with drag-and-drop capabilities. You also have quite a bit more control over where your BuddyPress components are now displayed. Here are the basic steps to setting up your main site navigation after BuddyPress is installed. (*Please note that this only applies to BP 1.5+)
Step 1: Assign BuddyPress components to their own pages.
If you want to house a component under a unique page name, then you will need to create that page first. For example, let』s say you want 「Forums」 to be accessed on a page called 「Discussion」. Create a blank page titled 「Discussion」 first.
Navigate to Dashboard > BuddyPress > Pages

Assign each of your active components to a page using the dropdown menu.
Step 2: Create your main navigation menu.
You can create your own customized menu for your BuddyPress site, just like you normally would with WordPress.
Go to Dashboard > Appearance > Menus
Create a new menu by giving it a title and dragging and dropping your desired pages.

To add links specific to the logged-in user, enable the 「BuddyPress」 option box:

And select the items you would like to add to your menu:

Step 3: Assign your menu as the primary navigation.
The default BuddyPress theme supports one menu – the primary navigation. Go to Theme Locations within the menu creation area and assign the menu you just created as the Primary Navigation for your site. Click save and refresh your site to see your new custom menu in place.

定制 (Customizing)

定制 (Customizing)

Codex Home → Getting Started → Customizing
Customizing

There are various ways to customize your BuddyPress site:

BuddyPress plugins in the WordPress.org repository
create your own plugin or
develop a custom theme

The BuddyPress forums offer up many code snippets and solutions from the community to help you add that extra functionality.
External Resources
http://wordpress.stackexchange.com/questions/tagged/buddypress

groups_group_create_complete()

groups_group_create_complete()

Codex Home → Developer Resources → Function Examples → groups_group_create_complete()
groups_group_create_complete()

Quick Note on group creation,
When a group first gets created it fires multiple actions some times multiple times.
For example, groups_create_group and groups_created_group fire first on the initial details page, and AGAIN when the group is actually created.
To bind to when the group is ACTUALLY created use groups_group_create_complete.
so:
?1add_action( 'groups_group_create_complete',  'my_function' );

默认主题更改日志

默认主题更改日志

Codex Home → Legacy Docs → Archived Section: Theme Development → The BuddyPress Default Theme → Default Theme Changelog
Default Theme Changelog

Archived file. Good up to BP 1.5 version

v1.5
A lot of new features.  To read about them, view the 「Highlights」 section on the 1.5 release page.
For those upgrading their theme to BuddyPress 1.5, please read the issues and solutions listed here:
https://codex.buddypress.org/releases/1-5-developer-and-designer-information/#theme
v1.2.9

jQuery 1.6.1 fixes for WordPress 3.2
jQuery Easing Plugin updated to 1.3
jQuery bgiframe.js updated to 2.1.2

To view which files were changed, please view the following link: https://buddypress.trac.wordpress.org/changeset?old_path=%2Ftags%2F1.2.8/bp-themes/&old=4619&new_path=%2Ftags%2F1.2.9/bp-themes&new=4619
v1.2.8

No changes!

v1.2.7

(Altered) Changed tab index on form elements in sidebar.php
(Altered) Secondary avatars will now not be generated for blog activity stream entries.

For a full list of changes, please view the following link: (https://buddypress.trac.wordpress.org/changeset?new=3422%40branches/1.2/bp-themes/bp-default&old=3407%40branches/1.2/bp-themes/bp-default — tbc)
v1.2.6

(New) Secondary avatars in the activity stream

To remove them, read this thread.

(New) Introduction of 「BP_Button」 class

This removes all hard-coded instances of the 「generic-button」 links in the theme
If you made changes to any of the following files in your theme, please make revisions as needed:

/members/single/member-header.php
/members/members-loop.php
/groups/groups-loop.php

(New) Ability to remove a member from a group (not ban)
(New) Pagination at the botton of all directory pages
(New) Miscellaneous new actions (see full list of changes linked below)
(Altered) Activity commenting CSS styles
(Altered) Javascript translation strings
(Altered) Zebra striping for tables
(Altered) Comment number count on blog posts
(Altered) Deprecate is_site_admin() function calls ( now uses is_super_admin() )

For a full list of changes, please view the following link:
https://buddypress.trac.wordpress.org/changeset?new=3296%40branches%2F1.2%2Fbp-themes%2Fbp-default&old=3124%40branches%2F1.2%2Fbp-themes%2Fbp-default

建立子主题 (传统)

建立子主题 (传统)

Codex Home → Legacy Docs → Archived Section: Theme Development → The BuddyPress Default Theme → Building a Child Theme (Legacy)
Building a Child Theme (Legacy)

Archived file. Good up to BP 1.5 version

Creating your own unique site design or theme is extremely simple to do, thanks to the Parent-Child functionality available in BuddyPress. This step-by-step guide will help you build your own custom theme. BuddyPress themes include more templates than your standard WordPress theme, However, these templates follow exactly the same structure as WordPress templates.
Child Themes: What is the point? Why not just create a brand new theme?
Building a child theme is the easiest and most future-proof way of building a BuddyPress theme. You can take advantage of an existing theme』s functionality, tweaking it to suit your own needs. By extending the default BuddyPress theme, you inherit all of the templates, JS, AJAX and if you wish, the CSS, all while preserving the core bp-default theme files. When new versions of BuddyPress are released with an updated default theme, your theme will automatically update along with it!
You can override any Parent theme template simply by either (1) copying it into your child theme and tweaking it or (2) creating a new, 「same-name」 template file in your Child theme directory. You can also add your own CSS, JS and AJAX features. For more information about Child themes, please go to the WordPress Codex page.
Let』s Start Building
The default BuddyPress theme is not located in the usual /wp-content/themes/ directory. It is stored in the BuddyPress plugin folder so it can be updated along with the plugin. WordPress knows where it is, even though your own theme is in /wp-content/themes/.
The first step is to create a new theme folder in /wp-content/themes/ and give it a unique name. For this example, the theme is called 「dusk」. In this new folder, create a file and call it 「style.css.」 This will be your child theme』s stylesheet.
Open up 「style.css」 and add the following code to the header, replacing necessary details with your own.
/*
Theme Name: BuddyPress Dusk
Theme URI: http://example.org/themes/dusk/
Description: Dark theme for BuddyPress.
Version: 1.0
Author: John Doe
Author URI: http://example.org/
Template: bp-default
Tags: buddypress, two-column, grey, dark
*/

Note the 「Template:」 entry, which tells WordPress that we want to use the BuddyPress default theme (bp-default) as the parent theme, and inherit all templates from it. You』ll also notice the 「Tags:」 line and the tag 「buddypress」. This will tell BuddyPress that you are using a BuddyPress capable theme so it won』t nag you in the admin area.
Save the file, and at this point, let』s activate the new theme. In the WordPress admin area, 「Appearance」 menu, you should see your new theme in the list of themes (if you don』t see it, and you』re using WordPress MU, make sure you』ve enabled the theme in 「Site Admin > Themes」). Go ahead and activate the new theme.
Check your site home page. You』ll notice that there is no design at all. It』s just text on a white page, possibly with a mangled header image. This is great, exactly what we want. This means your new child theme is working correctly and inheriting all of the template files. If you click around the site you』ll notice it still works, just with no design.
Inheriting CSS
At this point you have an important decision to make, you can start writing your own CSS from scratch, or you can inherit the default theme』s CSS and work from there. If you』re going to make a radically new theme design, you might want to start with a fresh slate. However, if you simply want to change the color scheme, and perhaps alter the layout a bit, I would highly recommend inheriting the CSS.
If you decide to inherit the CSS, you will need to add the following lines to your 「style.css」 file (below the comment header):
/* Inherit the default theme styles */
@import url( ../../plugins/buddypress/bp-themes/bp-default/_inc/css/default.css );
/* Inherit the default theme adminbar styles */
@import url( ../../plugins/buddypress/bp-themes/bp-default/_inc/css/adminbar.css );

Once you』ve added these lines, try reloading your home page again. You』ll notice that the design has gone back to the design of the default theme. This is perfect, you can now start making design adjustments in your own theme by adding your own CSS styles below this line. If you』ve decided to not inherit the CSS, then you can just start adding your own styles right below the header comment.
Overriding and Adding Template Files
By default your child theme will inherit all the template files in the default theme. What if you wanted to change some of the HTML though? Most design and layout changes can be done in the CSS, but if you really need to change some of the structure then you can override template files.
As an example let』s override the header.php template file. The first step is to head to the BuddyPress plugin folder (usually /wp-content/plugins/buddypress/) and then to the bp-themes/bp-default folder. In this folder you』ll see the header.php file, copy this file and paste it directly into your child theme』s folder (the same place as your style.css file). You can now make any edits to the HTML you wish and these will be reflected in your child theme. The header.php file in your child theme is essentially replacing the one in the parent.
You can do this with any template file in the parent theme. However, if you want to override a template file that is in a sub folder, you must also recreate the sub folder in your child theme.
functions.php
There is one exception to the template override rule – functions.php. If you create a blank functions.php file in your child theme, the parent theme functions.php will still be loaded. This will allow you to inherit existing functions, but also add your own. You must make sure you give your child theme functions a unique name, otherwise they will clash with the parent.
That is really all there is to creating child themes! I hope you found this guide useful, and remember that if you build your themes in this way, you are going to find upgrading BuddyPress much easier in the future.

Importing Data

Importing Data

Codex Home → Getting Started → Importing Data
Importing Data

Importing from Ning
Many users have been interested in being able to import their Ning social network into BuddyPress. This has been even more true since Ning started charging to use their service. Much of the heavy lifting of importing your Ning network to BuddyPress can be done using this Import from Ning Plugin.