Search Results for 'Permalink post_id'
-
AuthorSearch Results
-
May 12, 2008 at 5:21 am #64781
In reply to: bb_query: get topics started within a date range?
mrhoratioMemberHey Sam, thanks for making a ticket for this. I was able to query for topics within a date from directly from WordPress as well. Here’s something I wrote to merge “super sticky” bbPress topics into the WordPress loop. It’s a bit of hack, but it brings the “Promote to Front Page” functionality of Drupal into WordPress/bbPress:
<?php get_header(); ?>
<?php
//Put WordPress posts into an array
$wp_posts = $posts;
if (!is_single()){
//Retrieve first post of previous page (we need this post's date to query bbPress topics
$offset=$paged*$posts_per_page+$posts_per_page;
$first_post_of_previous_page = get_posts('numberposts=1&offset='.$offset);
//First set the start and end dates to limit the query to the bbPress table
$startdate=(date('YmdHis',strtotime($first_post_of_previous_page[0]->post_date_gmt)));
//If it's the most recent page, set end date to today
if ($paged){
$enddate=(date('YmdHis',strtotime($wp_posts[0]->post_date_gmt)));
} else {
$enddate=gmdate('YmdHis');
}
//Retrieve "Super Sticky" topics from bbPress tables
//This assumes your bbPress and WordPress tables are in the same database
$bb_topics = $wpdb->get_results("SELECT * FROM bb_topics WHERE topic_sticky = 2 AND topic_start_time BETWEEN $startdate AND $enddate ORDER BY topic_start_time DESC");
//Map bbPress topics to WordPress posts structure
foreach($bb_topics as $bb_topic){
$bb_first_post = $wpdb->get_results("SELECT post_text FROM bb_posts WHERE post_position = '1' AND topic_id = $bb_topic->topic_id", ARRAY_A);
$bb_post->ID = "forum_topic_".$bb_topic->topic_id;
$bb_post->post_author = $bb_topic->topic_poster;
$bb_post->post_date = $bb_topic->topic_start_time;
$bb_post->post_content = $bb_first_post[0][post_text];
$bb_post->post_title = $bb_topic->topic_title;
$bb_post->post_status = "publish";
$bb_post->comment_status = "open";
$bb_post->ping_status = $bb_topic->post_id;
$bb_post->post_name = "forums/topic/".$bb_topic->topic_slug;
$bb_post->post_type = "post";
$bb_post->comment_count = $bb_topic->topic_posts-1;
//add bbPress topic to WordPress posts array
$wp_posts[] = $bb_post;
};
//Create function to sort array of posts by date
function compare($x, $y){
if ( $x->post_date == $y->post_date )
return 0;
else if ( $x->post_date < $y->post_date )
return 1;
else
return -1;
}
//Sort array
usort($wp_posts,'compare');
}
?>
<div id="content-box" class="span-8">
<div id="content-area" class="clearfix">
<?php if ($wp_posts): ?>
<?php foreach ($wp_posts as $post): ?>
<?php setup_postdata($post); ?>
<div class="entry">
<div class="entry-header clearfix">
<div class="info span-2">
<a href="<?php the_permalink(); ?>#comments" class="comment-activity"><?php comments_number('<strong>Post comment</strong>', '<strong>1</strong> Comment', '<strong>%</strong> Comments' );?></a>
</div><!-- end info -->
<div class="content span-6 last">
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
</div><!-- end content -->
</div><!-- end entry-header -->
<div class="entry-content clearfix">
<div class="info span-2 clearfix">
<p><strong><?php the_author() ?></strong><br />
<?php the_time('M j, Y'); ?>
</p>
<p class="share-this"><?php akst_share_link(); ?></p>
<p class="post-comment"><a href="<?php the_permalink(); ?>#respond">Comment</a></p>
</div><!-- end info -->
<div class="content span-6 last clearfix">
<?php the_content('Click to continue'); ?>
<p class="entry-tags"><?php the_tags('<strong>Posted in: </strong>', ', ', ''); ?> </p>
</div><!-- end content -->
</div><!-- end entry-content -->
</div><!-- end entry -->
<?php endforeach; ?>
<?php include (TEMPLATEPATH . '/navigation.php'); ?>
<?php else : ?>
<h2 class="page_header center">Not Found</h2>
<div class="entry">
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
</div>
<?php endif; ?>
</div><!-- end content-area-->
</div><!-- end content-box -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>February 25, 2007 at 3:38 pm #54691In reply to: Display latest post from WP
nickbradyMemberHi,
I am writing a plugin for BBPress that shows the latest posts from WP (if WP and BBPress are sharing the same database). It’s still in development, but it already works, you just have to write
<?php wp_show_posts(\"\" ); ?>
in any BBpress template.
As you will see, it works, but it has a problem: it does not show WP’s pretty URLs. I would like to call WP’s get_permalink() function, but it uses many WP functions that are not available when you’re in BBPress.
Any advice on how to do this? Or maybe it would be easier to read WP’s RSS?
Thanks!
Here goes the code of the plugin so far (if you don’t care about pretty permalinks, you can use it, it works):
<?php
/*
Plugin Name: WP Posts
Plugin URI: http://thesandbox.wordpress.com
Description: Get a list of WordPress posts from your bbPress (needs to be integrated with WP, sharing database)
Author: Nick Brady
Version: 0.1
Author URI: http://thesandbox.wordpress.com
Install Instructions:
- If you don't have a /my-plugins/ directory in your bbpress installaltion, create it on the same level as config.php.
- Check out: https://codex.wordpress.org/Template_Tags/get_posts
*/
function wp_get_posts($args) {
global $bbdb, $bb;
parse_str($args, $r);
if ( !isset($r['numberposts']) )
$r['numberposts'] = 5;
if ( !isset($r['offset']) )
$r['offset'] = 0;
if ( !isset($r['category']) )
$r['category'] = '';
if ( !isset($r['orderby']) )
$r['orderby'] = 'post_date';
if ( !isset($r['order']) )
$r['order'] = 'DESC';
$now = bb_current_time('mysql');
$posts = $bbdb->get_results(
\"SELECT DISTINCT * FROM \".$bb->wp_table_prefix.\"posts \" .
( empty( $r['category'] ) ? \"\" : \", \".$bb->wp_table_prefix.\"post2cat \" ) .
\" WHERE post_date <= '$now' AND (post_status = 'publish') \".
( empty( $r['category'] ) ? \"\" : \"AND \".$bb->wp_table_prefix.\"posts.ID = \".$bb->wp_table_prefix.\"post2cat.post_id AND \".$bb->wp_table_prefix.\"post2cat.category_id = \" . $r['category']. \" \" ) .
\" GROUP BY \".$bb->wp_table_prefix.\"posts.ID ORDER BY \" . $r['orderby'] . \" \" . $r['order'] . \" LIMIT \" . $r['offset'] . ',' . $r['numberposts'] );
return $posts;
}
function wp_show_posts( $args ) {
global $bb;
$posts = wp_get_posts( $args );
foreach( $posts as $post ) {
echo \"<li>n\";
echo \"<a href='\".$bb->wp_home.\"?p=\".$post->ID.\"'>\";
echo $post->post_title;
echo \"</a><br/>n\";
echo \"</li>n\";
}
}
?>
-
AuthorSearch Results