Forum Replies Created
-
Cool – adds that extra level of usability, nice one!
Have cleaned up the code and plugged in the code suggested by @hnla – gets rid of the need for implode/explode and also allows for the list of tags from the member profile to be live:
`
<?php //for use in the loop, list 5 post titles related to user profile interest areas
$backup = $post; // backup the current object
//Fetch profile tags from custom field ‘Areas of Interest’
$profileTagFull = xprofile_get_field_data( ’25’ , bp_loggedin_user_id() );//Fetch the text for the tags$profileargs=array(
‘tag_slug__in’ => $profileTagFull,
‘post__not_in’ => array($post->ID),
‘showposts’=>5,
‘orderby’ => rand,
‘order’ => DESC,
‘caller_get_posts’=>1
);
?>Content of Interest
- <a href="tag/”>
-
<?php
- cat_name . ‘: ‘; ?><a href="” rel=”bookmark” title=””>
- No related content
$profile_query = new WP_Query($profileargs);
if( $profile_query->have_posts() ) {
while ($profile_query->have_posts()) : $profile_query->the_post(); ?><?php endwhile;
} else { ?><?php }
$post = $orig_post;
wp_reset_query();
?>`
This is my CSS for the run-in list:
`
.comma-list ul, .comma-list li {
color: #ffffff;
font-size: 10px;
text-transform: uppercase;
display: inline;
line-height: 12px;
}.comma-list li {
text-decoration: underline;
}
`Looks a lot neater now – thanks!
Bear in mind the original code is simply a modification of the ‘related posts’ code from WPRecipes (http://www.wprecipes.com/how-to-show-related-posts-without-a-plugin) with additional modifications from elsewhere on this support forum (forgive me, but I can’t recall where I picked it up from).
My coding isn’t the best in the world, but I know what I needed to achieve so feel free to tidy up, etc.In theory, you could use the extended profile to gather all sorts of information (location, language, favourite food) depending on your member base and site content and then modify this code to deliver highly personalised content based on this meta data (as long as your tagging is in place).
Feel free to use and abuse, like I said it a combo from various sources so I can’t claim any rights to it! Go forth and personalise!
It’s to help deliver content that is of personal interest to the registered member based on their profile information, rather than just the normal ‘related content’ – personalisation of content is key, makes your site more relevant to the individual, increasing loyalty and stickiness.
Doh! You know, I was using explode() later on to extract the individual elements – don’t know why I didn’t think of using implode() to clean up the array.
Thanks @hnla – that works now. For reference, here is the full code – basically this uses the data derived from checkboxes in the member’s profile (in this case it’s called “Areas of Interest” with the field ID of 25 – change this to reflect your name/field ID) to hunt down related content tags and display a random list of content relevant to that member (remember to put the code mentioned by @boonebgorges (above) in your theme’s functions.php):
`
<?php //for use in the loop, list 5 post titles related to user profile interest areas – checkboxes in extended profile
$backup = $post; // backup the current object
//Fetch profile tags from custom field ‘Areas of Interest’ and clean up data
$profileTagFull = xprofile_get_field_data( ’25’ , bp_loggedin_user_id() );//Fetch the text for the tags
$profileTagClean = implode( ‘, ‘, $profileTagFull);//Clean up the data$profileargs=array(
‘tag_slug__in’ => explode( ‘, ‘, $profileTagClean ),
‘post__not_in’ => array($post->ID),
‘showposts’=>5,
‘orderby’ => rand,
‘order’ => DESC,
‘caller_get_posts’=>1
);
?>
Content of Interest
()-
<?php
- cat_name . ‘: ‘; ?><a href="” rel=”bookmark” title=””>
- No related content
$profile_query = new WP_Query($profileargs);
if( $profile_query->have_posts() ) {
while ($profile_query->have_posts()) : $profile_query->the_post(); ?><?php endwhile;
} else { ?><?php }
$post = $orig_post;
wp_reset_query();
?>`
Thanks to @hnla @r-a-y and @boonebgorges for their help.So, anyone got any ideas on how to clean up this array and get it to show as a comma-separated list?
Brilliant, now `printr($profileTagFull)` returns `ARRAY ( [0] => COMMUNICATIONS [1] => TECHNOLOGY )` so I now need to clean this up into a comma separated list.
Thanks for your help (I put it in the theme’s functions.php by the way)
This has to be something to do with the serialization of the data in the database field, surely? I’ve tried `maybe_unserialize` and `unserialize` but with no luck.
Also, this data returns fine in the member’s profile (“) but of course this doesn’t allow me to specify a particular field id to use.
The same thing happens – it simply returns the word “Array” – the same if I use `print_r($profileTagFull);`
This was working fine until the 1.2.6 upgrade which is why my suspicions are that the process of how to read xprofile field data if it was created via checkboxes has changed.
Note that the code works fine if the xprofile field data contains text rather than the following (for example): `a:2:{i:0;s:10:”Governance”;i:1;s:8:”Training”;}`
Just wanted to bump this as it’s vitally important I get it fixed
Thanks