INSERT CONTENT HOMEPAGE POSTS WORDPRESS PHP PROGRAMMING

Insert content on your homepage blogroll in WordPress by programming it in PHP. Its fairly easy and we will provide the codes for you right here. Keep in mind that you should only do this to a child theme. In the tutorial I demonstrated it on a parent theme. Follow the same procedure and edit the same files in your child theme and it will work for you.

INSERT CONTENT AFTER LOOP IN BLOGROLL

Find the index.php file in your theme folder. It will have a loop. The code will look something like this but your could be slightly different.

Only cool people share!

[code]/* Start the Loop */
while ( have_posts() ) :
the_post();
[/code]

We want to edit that to look like this. First we start with a count outside the loop. We set it to 0. Then inside the loop we will put an if condition. If the count hits the 0 or 3 number we will have it display our widgets.

[code] /* Start the Loop */
$ct=0;
while ( have_posts() ) :
the_post();
get_template_part( ‘template-parts/post/content’, get_post_format() );
if($ct==0){
if ( ! dynamic_sidebar( ‘Home Page Widget’ ) );
}elseif($ct==3){
if ( ! dynamic_sidebar( ‘Home Page Widget Two’ ) );
}
$ct++;
endwhile;[/code]

Creating our Widgets To Use On Homepage

Now lets create the widgets that we will use on the home page blog roll. This will give us a space to use in the dashboard under widgets.

[code] /*adding widgets on home page*/
register_sidebar( array(
‘name’ => __( ‘Home Page Widget’ ),
‘id’ => ‘homepage-widget’,
‘description’ => __( ‘Widget shows after first post on home page.’ ),
‘before_widget’ => ‘
<div id="the-maximus-widget">’,
‘after_widget’ => "</div>

",
‘before_title’ => ‘
<div id="the-maximus-widget-title">’,
‘after_title’ => ‘</div>

‘,
) );
register_sidebar( array(
‘name’ => __( ‘Home Page Widget Two’ ),
‘id’ => ‘homepage-widget-two’,
‘description’ => __( ‘Widget shows after fouth post on home page.’ ),
‘before_widget’ => ‘
<div id="the-maximus-widget">’,
‘after_widget’ => "</div>

",
‘before_title’ => ‘
<div id="the-maximus-widget-title">’,
‘after_title’ => ‘</div>

‘,
) );[/code]

Inserting Content In Genesis WordPress CMS

The process for doing this in the Genesis Framework is a little different. Put this entire code in your functions.php child theme file and you are good to go!

[code] /*adding widgets on home page*/
register_sidebar( array(
‘name’ => __( ‘Home Page Widget’ ),
‘id’ => ‘homepage-widget’,
‘description’ => __( ‘Widget shows after first post on home page.’ ),
‘before_widget’ => ‘
<div id="the-maximus-widget">’,
‘after_widget’ => "</div>

",
‘before_title’ => ‘
<div id="the-maximus-widget-title">’,
‘after_title’ => ‘</div>

‘,
) );

register_sidebar( array(
‘name’ => __( ‘Home Page Widget Two’ ),
‘id’ => ‘homepage-widget-two’,
‘description’ => __( ‘Widget shows after third post on home page.’ ),
‘before_widget’ => ‘
<div id="the-maximus-widget">’,
‘after_widget’ => "</div>

",
‘before_title’ => ‘
<div id="the-maximus-widget-title">’,
‘after_title’ => ‘</div>

‘,
) );

/*code to display widget genesis only*/
add_action( ‘genesis_after_entry’, ‘addtl_widget_area’ );
function addtl_widget_area() {
global $loop_counter;
$loop_counter++;
if( (!is_paged() && !is_singular()) && ($loop_counter == 1)) {
if ( ! dynamic_sidebar( ‘Home Page Widget’ ) );
$loop_counter = $loop_counter + 1;
}
if( (!is_paged() && !is_singular()) && ($loop_counter == 4)) {
if ( ! dynamic_sidebar( ‘Home Page Widget Two’ ) );
$loop_counter = $loop_counter + 1;
}
}[/code]

INSERT CONTENT HOMEPAGE POSTS WORDPRESS PHP PROGRAMMING was last modified: November 10th, 2018 by Maximus Mccullough
putting-content-inbewteen-posts-wordpress

1 Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.