The MU forums have moved to WordPress.org

Featured Post (61 posts)

  1. DailyTestimony
    Member
    Posted 16 years ago #

    lol...I bet that will fix it, I uploaded the new code but for some reason the page won't display I get an Internet Explorer Cannot Display This Page for any part of my sitee but I can access my cpanel just fine...the wiered thing is I'm not getting anything in my apache error log or my WPMU error log. I know its not a DNS issue because my cpanel is on the same domain.

    It's something wierd on my hosts end I guess because I used an online service to check my site and it couldn't connect either. I emailed them and so hopefully it will be fixed soon.

  2. DailyTestimony
    Member
    Posted 16 years ago #

    According to my host...the server I on:

    Currently offline. There is a bug in the CPanel system and we are waiting for CPanel fix the issue. We have several urgent tickets open with them.

    I am really starting to question them as a host...

  3. DailyTestimony
    Member
    Posted 16 years ago #

    Well my site is back up, but that still does not work.

  4. infoclipper
    Member
    Posted 16 years ago #

    Did the error message change at all? And can you post your latest code up so I can have another look? Also, how exactly are you calling your code on the site?

  5. DailyTestimony
    Member
    Posted 16 years ago #

    <?php
    /*
    Plugin Name: Featured-Post
    Plugin URI: http://dailytestimony.net/plugins/featured-post.php
    Description: Selects randomly one of the blogs provided and gets the most recent post from it
    Author: Daily Testimony
    Author URI: http://dailytestimony.net/
    License: Creative Commons Attribution-Share Alike 3.0 United States
    License URI: http://creativecommons.org/licenses/by-sa/3.0/us/
    Version: 0.1beta
    */
    
    function featured_post(){
    	global $wpdb;
    
    	$featured_blogs = array(1,2); //Update this array with the ID's of featured blogs
    	srand(time()); //Do not change this
    	$random = (rand() % count($featured_blogs)); //Update this with the number of entries in the array above
    
    	$thispost = $wpdb->get_results("SELECT id FROM " . $wpdb->posts . " WHERE post_status = 'publish' AND post_type = 'post' ORDER BY id DESC LIMIT 0,1");
    
    	$featured_post = get_blog_post($featured_blogs[$random], $thispost);
        $post_author_id = $featured_post->post_author;
    	$post_author = $wpdb->get_results("SELECT display_name FROM wp_users WHERE id = $post_author_id");
    	$permalink = get_blog_permalink($featured_blogs[$random], $thispost);
    	$blog_url = get_blogaddress_by_id($featured_blogs[$random]);
    
    	$blog_table = 'wp_' . $featured_blogs[$random] . '_options';
    	$blog_name = $wpdb->get_results("SELECT option_value FROM $blog_table WHERE option_name = 'blogname'");
    
    	$content = explode(' ',$featured_post->post_content);
    	for($i=0; $i<200; $i++){
    		$summary[$i] = $content[$i];
    	}
    	$summary = implode(' ', $summary);
    
    	//Lets Output the Post ?>
    	<div class="entry">
    	<div class="entrytitle">
    	<h1><a href="<?php echo $permalink; ?>" rel="bookmark" title="Link to <?php $featured_post->post_title; ?>"><?php $featured_post->post_title; ?></a></h1>
    	<div class="endate"><?php echo $post_author; ?> on <?php date('F jS, Y', $featured_post->post_date); ?></div>
    	</div>
    
    	<div class="entrybody">
    	<?php echo $summary; ?><a href="<?php echo $permalink; ?>" rel="bookmark" title="Link to <?php $featured_post->post_title; ?>">More...</a>
    	</div>
    
    	<p align=right>
    	<div class="entrymeta"><div class="postinfo" align="right">
    	<a href="<?php echo $blog_url; ?>"><?php echo $blog_name . '>>>'; ?></a>
    	</div>
                    </div>
                    </div>
    	</p>
    <?php
    };
    ?>

    I call it on home.php with

    <?php featured_post(); ?>

    You can see exactly how it's currently displaying on my site http://dailytestimony.net

  6. DailyTestimony
    Member
    Posted 16 years ago #

    hmm any other ideas? My only though is it would be a misuse of the get_blog_post() function since their are no docs on it I kinda just winged it and may have gotten that wrong.

  7. DailyTestimony
    Member
    Posted 16 years ago #

    ok well seriously I don't mean to be disrepectful or anything by bumping this...again...but I really need someones help on this. Where are the PHP guru's when I need them?

  8. DailyTestimony
    Member
    Posted 16 years ago #

    Well a quick search of wpmu-functions.php finds the function code which is:

    function get_blog_post( $blog_id, $post_id ) {
    	global $wpdb;
    
    	$key = $blog_id."-".$post_id."-blog_post";
    	$post = wp_cache_get( $key, "site-options" );
    	if( $post == false ) {
    		$post = $wpdb->get_row( "SELECT * FROM {$wpdb->base_prefix}{$blog_id}_posts WHERE ID = '{$post_id}'" );
    		wp_cache_add( $key, $post, "site-options", 120 );
    	}
    
    	return $post;
    
    }

    Though with my limited PHP knowledge I couldn't find out correct useage from this, maybe someone else can tell though.

  9. RCB-IT-Solutions
    Member
    Posted 16 years ago #

    this would be interesting to see finished.

  10. DailyTestimony
    Member
    Posted 16 years ago #

    Yeah I am hoping to get this resolved ASAP and then i'll ut this code up for download for others to use as well.

  11. infoclipper
    Member
    Posted 16 years ago #

    Sorry; pretty much down from the flu.

    Just ran across this again and saw your latest update. Too groggy to debug code, but maybe these notes will help you out:

    That function expects:

    The desired blog ID (i.e., the output of your random blog grab) and the ID number of a post on that blog. So basically, you need to know the ID number of the latest post on the blog, then pass it into this function.

    The output will be a class containing the elements of the post.

    Given that, I think your problem is here:

    ...
    $thispost = $wpdb->get_results("SELECT id FROM " . $wpdb->posts . " WHERE post_status = 'publish' AND post_type = 'post' ORDER BY id DESC LIMIT 0,1");
    $featured_post = get_blog_post($featured_blogs[$random], $thispost);
    ...

    In the above, $thispost isn't a scalar, it's an object. Change the $wpdb->get_results call to $wpdb->get_value and see if things improve for you.

    Hope this helps!

  12. DailyTestimony
    Member
    Posted 16 years ago #

    It just spits out an error saying Fatal error: Call to undefined method wpdb::get_value()

  13. infoclipper
    Member
    Posted 16 years ago #

    D'oh!

    Warned you I was sick.

    I meant: $wpdb->get_var()

    Sorry about that.

  14. DailyTestimony
    Member
    Posted 16 years ago #

    Hmm I'm getting the same output as I did using $wpdb->get_results

  15. DailyTestimony
    Member
    Posted 16 years ago #

    Interesting...Now it's mostly working.

    It still says Array On, and instead of saying the blogname for the link to it, it just says Array.

    and I am not getting the title, author, or post date info though.

    EDIT: I see why it didn't look like it was working earlier. It works partially if its the admin blog, and not at all if it's my personal blog.

    I think that may be caused by the fact somehow that the permalink column is empty for my recent blog post of my personal blog but not on the admin blog.

  16. DailyTestimony
    Member
    Posted 16 years ago #

    well I was playing with the code and now it dislays the stuff from both blogs...it was due to the permalink not working, now instead of getting the permalink from the db though a function, I use (blog-url)/index.php?p=(post-id) to link to the post and that works perfectly. I also change the other get_results to get_var and a few other minor changes and it seems to be working better, I still am not getting the blog post title.

    Also the date I am getting is not accurate, its giving me December 31st, 1969

    For the date if i just echo $featured_post->post_date then it gives me the right date but the wrong format.

    echoing date('F jS, Y', $featured_post->post_date) I though show reformat the date that way I want and it does format the date correctly but the date is wrong.

  17. DailyTestimony
    Member
    Posted 16 years ago #

    any ideas?

  18. DailyTestimony
    Member
    Posted 16 years ago #

    bump

  19. demonicume
    Member
    Posted 16 years ago #

    could you give us access to what youre working with so far?

  20. DailyTestimony
    Member
    Posted 16 years ago #

    any suggestions?

  21. DailyTestimony
    Member
    Posted 16 years ago #

    anyone have any idea whats causing my problems?

  22. DailyTestimony
    Member
    Posted 16 years ago #

    *bump*

  23. lunabyte
    Member
    Posted 16 years ago #

    From a week ago:

    "could you give us access to what youre working with so far?"

  24. DailyTestimony
    Member
    Posted 16 years ago #

    look at the link to the text file i posted before..the url again it's http://dailytestimony.net/plugins/debug/featured_posts.txt I've been keeping it up to date with each change I make to the code, sorry if that was not clear.

  25. MrBrian
    Member
    Posted 16 years ago #

    I don't feel like reading the whole thread as a lot of it sounds unclear anyway. I see the code, now what's the problem with it.

  26. DailyTestimony
    Member
    Posted 16 years ago #

    I still am not getting the blog post title.

    Also the date I am getting is not accurate, its giving me December 31st, 1969

    For the date if i just echo $featured_post->post_date then it gives me the right date but the wrong format.

    echoing date('F jS, Y', $featured_post->post_date) I thought would reformat the date that way I want and it does format the date correctly but the date is wrong.

  27. MrBrian
    Member
    Posted 16 years ago #

    If the date is wrong, it's wrong in the database. If it's wrong in the database, your server time is wrong or it's not storing correctly.

    As far as the post_title, your code is not even echoing it. That's why it's not displaying.

  28. DailyTestimony
    Member
    Posted 16 years ago #

    The date is right in the database, when I use

    echo $featured_post->post_date

    it is correct, but in the wrong format. I try to reformat it by using

    echo date('F jS, Y', $featured_post->post_date)

    Which based on me reading should take the value of $featured_post->post_date and format it to 'F jS, Y'.

    As far as the title thats a good catch I didn't notice that. Thanks for your help.

    EDIT: Well I did some more searching about the date issue seems I wasn't far off, I needed to do this

    echo date('F jS, Y', strtotime($featured_post->post_date))

    I just missed the strtotime() around the $featured_post->post_date

    Now this thread is rather full of alot of debugging stuff so later today when I get around to putting up this code to download for others to use I'll just make a new thread. Thanks again for ALL your help!

  29. kornpong
    Member
    Posted 16 years ago #

    How to show 3 Featured Post on frontpage?

  30. af3
    Member
    Posted 16 years ago #

    hey, tried using this and it's working fine except it throws this error:

    [25-Apr-2008 23:30:46] WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE option_name = blogname' at line 1]
    SELECT option_value FROM WHERE option_name = blogname

    seems like the random blog is empty. any idea?

About this Topic

  • Started 16 years ago by DailyTestimony
  • Latest reply from h1b_transfer