Table of Contents

WordPress Featured Content Pt 8

Here 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

fclose($ntt_fc_page_to_write);

8 Responses to “WordPress Featured Content Pt 8”

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?

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?

Your email address will not be published.

This content was originally published here.