Dynamic content on homepage

Posted in: Newspaper
Post count: 20

Hi, i have a little problem, may be you can help me.
I tried to create a original homapage, or may be just a header fullsize, but it is not the point.
I create a new php file with sublimetext, in that php file i put :

<?php
/*
Template Name: Home
*/
?>
<?php

get_header('home');

//set the template id, used to get the template specific settings - this was the old home.php template
$template_id = 'home';

//prepare the loop variables
global $loop_module_id, $loop_sidebar_position;
$loop_module_id = td_util::get_option('tds_' . $template_id . '_page_layout', 15); //module 1 is default
$loop_sidebar_position = td_util::get_option('tds_' . $template_id . '_sidebar_pos'); //sidebar right is default (empty)

// sidebar position used to align the breadcrumb on sidebar left + sidebar first on mobile issue
$td_sidebar_position = '';
if($loop_sidebar_position == 'sidebar_left') {
$td_sidebar_position = 'td-sidebar-left';
}
?>

<div class="img-header-home">
<div class="container mt-130 z-index100">
My static content
</div>
</div>

here

<?php
get_footer();

i put my php file in the hosting where wordpress are installed, and from wordpress, i create a page, and choose from template my php file “Home”.

now under My Content <div class = “img-header-home”> I want to add some dynamic content that retrieves items from my blog.
And if it can be added by visual composer on this page. Because I try to create content with but it does not appear online.
I think something is missing (i mean some code php) to recovered the visual composer tomake it works.
i understand html, css, but not more in php, that’s why i need your help.

i’m sorry my english is bad, I hope u can understand.

Thanks in advance.

Post count: 6535

Hi

Your code is missing the loop part which check if there are any post to be displayed on the page. A basic loop example it’s in this code:

<?php if ( have_posts() )  ?>
<?php while ( have_posts() ) : the_post(); ?>
    <div class="td-container">  //the theme uses this classes for
    <div class="td-container-border">  //post/page content
        <?php the_content(); ?>
        //you can place a custom code here, depending by your needs 
    </div>
    </div>
<?php endwhile; ?>

The theme display the page content using this classes: td-container, td-container-border You can replace them if you want but in this case you need to create your own css for layout. Also you can use your classes within theme’s classes like this:

<div class="td-container">  //the theme uses this classes for
    <div class="td-container-border">  //post/page content
        <div class="img-header-home">
        <div class="container mt-130 z-index100">
          My static content
          <?php the_content(); ?>
        //you can place a custom code here, depending by your needs 
        </div>
        </div>
   </div>
</div>

You can check this example code here: http://pastebin.com/8E0XZ8de which produce this result: http://screencast.com/t/p8SsR9P2x9Whttp://screencast.com/t/N95ikdPhHY
This is a basic example, but you can customize your page template as you need by ading different conditions in that file. For more information regarding WordPress loops you can check the official documentation: https://developer.wordpress.org/themes/basics/the-loop/

Hope this help.
Thanks!

  • This reply was modified 10 years by Andrei L..
Post count: 20

Thanks this help very much. Very usefull. Thanks u so much

Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newspaper’ is closed to new topics and replies.