Support » Theme: Smart Magazine » Loading content from template-parts

  • Resolved AlternativePhotography

    (@alternativephotography)


    Hello,
    Can someone please help? I need to create a specific template for a page called Events, but I can’t figure out how to do this.
    The theme is using template parts.

    This is the instructions in the index.php page:

    /*
    * Include the Post-Format-specific template for the content.
    * If you want to override this in a child theme, then include a file
    * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    */
    get_template_part( 'template-parts/content', get_post_format() );

    I’ve created a new template by copying the page.php page and calling it page-events.php.
    It includes this line:

    <?php get_template_part( 'template-parts/content', 'page', 'events' ); ?>

    I’ve added the template to the page in WordPress dashboard. BUT, my problem is I can’t seem to connect it to the content.

    The content of the template sits in a subfolder called “template-parts”.
    I’ve added a new page there based on content-page.php and renamed it content-page-events.php.
    But, whatever i put in the template file it does not show up. I’ve tried all sorts of variations like:
    ‘template-parts/content’, ‘page’, ‘events’
    ‘template-parts/content’, ‘page-events’, ‘events’
    ‘template-parts/content’, ‘page-events’
    and so on, but not been able to read it. Can someone please tell me what the correct way to do this is?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Theme Author Qaiser

    (@kais99)

    Please follow these steps.
    1: duplicate page.php and name it something like template-event.php add below line at the top of the page
    <?php /* Template Name: Example Template */ ?>
    You can read more about templates here

    2: Change this line <?php get_template_part( ‘template-parts/content’, ‘page’ ); ?> to <?php get_template_part( ‘template-parts/content’, ‘page-event’ ); ?>
    and duplicate template-parts/content-page.php and rename newly created file to template-parts/content-page-event.php
    You can add some dummy text to see if the correct template is loading. Here is the screenshot of the files.

    3: Assign you template to the event page from WordPress backend and update.

    Thanks,
    Qaiser

    AlternativePhotography

    (@alternativephotography)

    Thank you very much for your reply. I’ve done this exactly, and it looks like the page has the template in the dashboard.
    I’ve added dummy text to the page-events.php – sorry for the long code in this post, but I thought it’s better if I add the whole thing:

    <?php /* Template Name: page-events */ ?>

    <?php
    /**
    * The template for displaying all pages.
    *
    * This is the template that displays all pages by default.
    * Please note that this is the WordPress construct of pages
    * and that other 'pages' on your WordPress site will use a
    * different template.
    *
    * @package Smart Magazine
    */

    get_header(); ?>

    <div id="primary" class="content-area col-sm-8 col-main">
    <main id="main" class="site-main" role="main">

    <?php while ( have_posts() ) : the_post(); ?>

    <?php get_template_part( 'template-parts/content', 'page-events' ); ?>
    <p>Dummy text here</p>
    <?php
    // If comments are open or we have at least one comment, load up the comment template.
    if ( comments_open() || get_comments_number() ) :
    comments_template();
    endif;
    ?>

    <?php endwhile; // End of the loop. ?>

    </main><!-- #main -->
    </div><!-- #primary -->

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    and I’ve added dummy text to the content-page-events.php file in a few places:

    <?php
    /**
    * The template used for displaying page content in page-events.php
    *
    * @package Smart Magazine
    */

    ?>
    <p>Dummy text here</p>
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
    <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?><p>Dummy text here</p>
    </header><!-- .entry-header -->
    <?php if ( has_post_thumbnail() ) : ?>
    <div class="featured_image">
    <?php the_post_thumbnail( 'large' ); ?>
    </div><!-- featured_image-->
    <?php endif; ?>
    <div class="entry-content">
    <?php the_content(); ?>
    <p>Dummy text here</p>
    <?php
    wp_link_pages( array(
    'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'smart-magazine' ),
    'after' => '</div>',
    ) );
    ?>
    </div><!-- .entry-content -->

    <footer class="entry-footer">
    <?php edit_post_link( esc_html__( 'Edit', 'smart-magazine' ), '<span class="edit-link">', '</span>' ); ?>
    </footer><!-- .entry-footer -->
    </article><!-- #post-## -->

    I don’t get it to load… as you can see here:
    http://69.89.31.128/~malinfab/alt-proc/community/events-listings/
    Any ideas? 🙂 It would be much appreciated!

    Theme Author Qaiser

    (@kais99)

    Rename page-event.php to template-event.php and test.
    page-{slug}.php = page-event.php
    If no custom template has been assigned, WordPress looks for and uses a specialized template that contains the page’s slug. More info here.

    To debug, add dummy text in:
    1: template-event.php to see if you are loading correct template
    2: content-page-events.php to see if you are loading correct content.

    Let me know if there is any issue.

    AlternativePhotography

    (@alternativephotography)

    Great thanks, now it’s doing it. I didn’t call it “template-…” first because when i rename it that it says i don’t have access to edit the file. Weired.
    Anyhow, this problem solved now. Thank you so much for your help and for a great theme.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Loading content from template-parts’ is closed to new replies.