I’m new to BP and WP! I have a quick question:
How can I show a one-line bio beneath usernames in the list of members in the ‘Members’ page of my BuddyPress website? For example, Facebook has a similar feature; it shows a name with a description beneath, e.g. ‘John Smith’ with ‘Engineer at Nuts & Bolts Co’ right beneath it.
I found the following line of code in member-header.php:
<h2 class=”user-nicename”>#<?php bp_displayed_user_username(); ?></h2>1
I thought about adding another line beneath for the bio field, but I’m not sure what to replace “bp_displayed_user_username();” with – I don’t think there is a “bp_displayed_user_bio();”. Should I create it? If so, how?
Thank you for your time!
'member-header.php' is for single member pages.
If you want the bio to display on singe member pages, create a template overload.
Then add this:
<?php
$bio = xprofile_get_field_data('Bio');
//If the field is not called Bio, then change it above
if( !empty( $bio )
echo 'Bio: ' . $bio;
?>
If you want Bio to display on the members page that shows all members, then create a template overload of this page:
\buddypress\bp-templates\bp-legacy\buddypress\members\members-loop.php
And look for this: bp_member_profile_data( 'field=the field name' );
Uncomment it and change to to, for example, bp_member_profile_data( 'field=Bio' );
Related
Referring to How to get username/display name in Buddypress?
I have tried putting this code to an added new page
<?php
$string = bp_get_displayed_user_fullname();
echo $string;
?>
But when i tried previewing the page it prints empty only. Is there something I missed on the plugin to make it working? TIA
bp_get_displayed_user_fullname() will work only on pages, that are displaying some user. That means your profile or profiles of other users. On all other pages you will always see an empty string (forums, ordinary WordPress pages and posts, groups etc).
To display a name of any user on any page you need to use something like bp_core_get_user_displayname( $user_id ), where $user_id is, obviously, the ID of a user you want the name of.
I have a problem where WordPress isn't showing line breaks when I echo the user description. The text shows in one line.
I'm using this line of code to show the user description:
<?php $user = get_user_by( 'slug', 'admin' ); echo $user->description ?>
Any idea what could be causing the problem and how to get WordPress to show the line breaks in the user description? Adding <br /> to the description box on user profile settings page doesn't help.
I think you could do something like this:
echo nl2br($user->description);
To optimize things, you could plug it up so that your user description saves the string using nl2br when saved in the database.
Before I made the switch to Drupal (previously just static HTML), I had a div title in my header that changed depending on what page the user was on using the following code:
ABOUT PAGE
<?php
$title = "ABOUT US</span>";
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/includes/header.php";
include_once($path); ?>
The reason this worked, however, was because I was using static HTML... which means I had every page set to use its own Index.PHP, located at (for the About page, for example) public_HTML/about/index.php. Therefore, I could edit each page individually to my liking by editing its respective Index file...
Now, with Drupal.. instead of having so many Index.PHP files like I did before (which was messy IMO...), I want to have every page use the same page.tpl.php (with the exception of the front page, which uses page--front.tpl.php).
Can I somehow modify the above PHP code to display a different title using IF statements depending on what page the user is on?
For example... (I have no idea how to PHP code so this is just to give you experts an idea of what I would want..)
Ifpage=about, $title=About Us;
Ifpage=contact, $title=Contact Us;
Could this code all be in the same page.tpl.php?
Thank you so much!
Drupal 7 has a title field for each content type. Why don't you use that?
It shows by default and you can change it for every node.
It is this code in your template file.
<?php print render($title_prefix); ?>
<?php if ($title): ?>
<h1 class="title" id="page-title">
<?php print $title; ?>
</h1>
<?php endif; ?>
<?php print render($title_suffix); ?>
$title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
$title: The page title, for use in the actual HTML content.
$title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
See https://api.drupal.org/api/drupal/modules!system!page.tpl.php/7 for all the variables available in your page.tpl template file.
If you want to style one part different from the other you could use an extra field for it.
Or if you need to do something with the value (I wouldn't suggest this!!!).
switch ($title) {
case "About Us":
// Do something with the title
break;
case "Contact Us":
// Do something with the title
break;
case 2:
// Do something with the title
break;
}
Here's a simple approach:
Add a new field for the content type
Call it title2
Render the two fields
Use css to inline align them and add styling
Here was my solution since I am unable to position a Drupal-based title block right next to a non-Drupal based logo DIV..
I created a div called .headertitle and positioned/styled it how I want.
My header.php is an PHP include file which is called by each page and the headertitle has a PHP condition..
<?php if(empty($headertitle)) $headertitle = "ASK REAL QUESTIONS, <br><span class='white'>GET FREE ANSWERS.</span>";
echo $headertitle; ?>
That way, if no text is declared for the .headertitle, it takes the default form of "ASK REAL QUESTIONS, GET FREE ANSWERS."
...Now, I had to figure out a way to actually declare text for the .headertitle depending on what page I was on...
I did this by using a custom template for each page (node) by using this file.. "page--node--nodeid.tpl.php".
So, for my ABOUT US page, I created a tpl.php file called "Page--node--7.tpl.php".. for this page, the 7 is the nodeid which is easy to find.
Then, I added the following PHP code to declare text for the .headertitle specifically on the ABOUT US page which looks like this...
<?php $headertitle = "ABOUT<span class='white'>.US</span>"; include('includes/header.php'); ?>
DONE AND DONE.
I'll do that for each page. :)
I am attempting to make a custom query in Wordpress. I want to have it pull up any posts that are tagged relevant to the page that people are on. IE - If they are on the Bay 198 Skatepark page, they also see a list of all Bay 198 Skatepark posts.
I've gotten the custom query to work, but I need this to be dynamic so that if you are on the Bay 198 page, you see those posts, but if you are on the Precision Skateboards page, you see those specific posts.
The easiest way I could think to accomplish this was to create a custom field on each page that would be the same as the tag and that way I would just fill in the tag for each page as a custom field and it would return the posts.
The issue is that I can't figure out how to implement the custom key call into the custom query. Here's my code so far, this one being the one that works:
<?php $second_query = new WP_Query(' tag=bay-198&posts_per_page=500 '); while( $second_query->have_posts() ) : $second_query->the_post(); ?>
I just need to figure out how to replace that "tag=bay-198" and have it dynamically pull in the tag based on the page.
Hopefully that makes sense, I appreciate any help.
You can use a variable that containts the value of your custom field. Then add that variable into the query like so:
<?php
$mykey_values = get_post_custom_values('my_key');
$tag = $mykey_values['your-custom-field'];
$second_query = new WP_Query(' tag=' . $tag . '&posts_per_page=500 '); while( $second_query->have_posts() ) : $second_query->the_post(); ?>
So I am trying to add a "-none" to a class for a post if it is in a specific category in Wordpress. So like lets say if I am viewing a post that has a category id of 7, i want a certain class titled "example" change to "example-none".
Here's my code:
<div class="example<?= is_category('events') ?'-none':'' ?><?= in_category('7') ?'-none':'' ?>">
The weird thing with the code is, it works in a page when I am viewing all the posts in a specific category. But when I go to an interior post that is in a specific category, the code does not work.
I am using the in_category('7') tag to achieve this on a wordpress sidebar.
Any idea on what I am doing wrong?
I would remove the quotes around the id of the category:
in_category(7)
This should be a number, not a string.
Thanks. i got it working using this code:
<div class="example<? wp_reset_query(); ?><?= in_category(7) ?'-none':'' ?>">