WordPress Featured Content Pt 8

Wordpress Featured Content 8Here I finish what I started in part 7 of the WordPress Featured Content tutorial.

I’m focusing on how to dynamically create the featured content slider after a new post has been saved.

The main skills you’ll develop here, aside from how to make the slider, is how to keep your code very organized as you proceed through a complicated project.

If you missed part one of this tutorial check out WordPress Featured Content Part 1.

Like always the code follows the video. It is heavily commented and you can use it in anyway that you’d like.

Code From the Video

for ($ntt_i = 1; $ntt_i <= $ntt_num_fc_pages; $ntt_i++)


$ntt_start_post = ($ntt_i * 5) – 4;

$ntt_end_post = ($ntt_i * 5);


// Initialize beginning of page with the first title of first post

$ntt_fc_page = ‘<div class=”ntt_text_div”><div class=”ntt_article_title”>’ . $ntt_fc_info[$ntt_start_post][0] . ‘</div><div class=”ntt_horz_rule”></div><div class=”ntt_article_excerpt”>’;


for ($ntt_j = $ntt_start_post; $ntt_j <= $ntt_end_post; $ntt_j++)



$ntt_fc_page .= ‘<p title=”‘;


// Replace spaces in the title with dashes

$ntt_temp_title = str_replace(‘ ‘, ‘-‘, $ntt_fc_info[$ntt_j][0]);


// Make all the characters in the title lowercase

$ntt_temp_title = strtolower($ntt_temp_title);


// Place title into the title attribute for the paragraph

$ntt_fc_page .= $ntt_temp_title . ‘”>’;


// Retrieve the post excerpt

$ntt_fc_page .= $ntt_fc_info[$ntt_j][1] . ‘</p>’;




$ntt_fc_page .= ‘</div><div class=”ntt_read_more”>’;


// Create the read more tag and give it the first post url link

// This will be changed dynamically by JQuery

$ntt_fc_page .= ‘<a href=”‘ . $ntt_fc_info[$ntt_start_post][2] . ‘”>Read More</a>’;


$ntt_fc_page .= ‘</div></div><div class=”ntt_featured_pic”>’;


for ($ntt_j = $ntt_start_post; $ntt_j <= $ntt_end_post; $ntt_j++)


// Get the featured image, link to post and post title

$ntt_fc_page .= ‘<a href=”‘ . $ntt_fc_info[$ntt_post_num][2] . ‘”<img src=”‘ . $ntt_fc_info[$ntt_j][3] . ‘” alt=”‘ . $ntt_fc_info[$ntt_j][0] . ‘” /></a>’;




$ntt_fc_page .= ‘</div><div class=”ntt_thumb_box”>’;


for ($ntt_j = $ntt_start_post; $ntt_j <= $ntt_end_post; $ntt_j++)



$ntt_fc_page .= ‘<div class=”ntt_thumbnail_frame”>’;

$ntt_fc_page .= $ntt_fc_info[$ntt_j][4];




$ntt_fc_page .= ‘</div><div class=”ntt_left_button”><img src=”‘;


$ntt_fc_page .= $ntt_plugin_directory . ‘images/fc_left_arrow.png” alt=”Back” /></div><div class=”ntt_right_button”><img src=”‘;


$ntt_fc_page .= $ntt_plugin_directory . ‘images/fc_right_arrow.png” alt=”Next” /></div>’;


// I’ll use this to directly access the plugin folder when I upload this

// $ntt_print_to = plugins_url( ‘featured_data1.txt’, __FILE__ );


// When programming on a localhost you must reference the file directly

$ntt_print_to = ‘/Library/WebServer/Documents/wordpress/wp-content/plugins/NTTFeaturedContent2/featured_data’ . $ntt_start_post . ‘.txt’;


// Open the file I’m going to write to. If it doesn’t exist make it

$ntt_fc_page_to_write = fopen($ntt_print_to, “w”);


// Write the updated info to the file

fwrite($ntt_fc_page_to_write, $ntt_fc_page);


// Close the file after finished with the file





8 Responses to “WordPress Featured Content Pt 8”

  1. Simon says:

    I noticed that your code changes “quotes” to “quotes” and you can’t copy and paste it without changing everything.
    There’s a plugin called SyntaxHighlighter Evolved which gets rid of this problem and makes it more readable. It’s really easy to setup and use. (Just put the code between [language] and [/language])
    Just a suggestion 🙂

    • admin says:

      I’ll look into that. Sorry about the quote problem, but my site is constantly attacked and I worry about security issues. I’ll check out the plugin you mentioned. Thanks for pointing that out

  2. Simon says:

    It changed my quotes too but you know what I mean..

  3. it seems interesting……
    like to use.

  4. Ali says:

    Sir please help me. Warning: Cannot modify header information – headers already sent by (output started at /home/nokia/public_html/wp-includes/pluggable.php:28) in /home/nokia/public_html/wp-includes/pluggable.php on line 866

    It is usually because there are spaces, new lines, or other stuff before an opening tag,

    I am cheked the pluggable.php file. But in pluggable.php not spaces.

    How can solve our problem?

    • admin says:

      The extra space is not in pluggable it is in the code that you wrote. You shouldn’t change anything in the wp-includes folder because that could break wordpress. Not a big deal. You would just need to issue a wordpress update

  5. Ali says:

    MY wp-admin is not open. Warning: Cannot modify header information – headers already sent by (output started at /home/nokia/public_html/wp-includes/pluggable.php:28) in /home/nokia/public_html/wp-includes/pluggable.php on line 866

    Sir please tell me that how can update the wordpress without login to admin panel?

Leave a Reply

Your email address will not be published.