Skip Navigation

[Gelöst] Remove unwanted content from posts using Twentysixteen Theme

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
Single posts displayed with the twentysixteen theme contain elements that are not required, how can they be removed?

Solution:
Views Content Templates or Layouts only replace the part of the page rendered by the_content() function in the theme template files. To remove content outside of this area requires editing the theme files (unless the theme includes a theme options integration with Toolset).

For twentysixteen this is described below:

https://toolset.com/forums/topic/twentysixteen-theme-double-posts-in-layouts/#post-620580

This support ticket is created vor 6 Jahren, 9 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Dieses Thema enthält 6 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von jorg-andreasK vor 6 Jahren, 8 Monaten.

Assistiert von: Nigel.

Author
Artikel
#620395
Toolset double of content.png

I used to work with toolset and Divi in the past.

actually I want to use Toolset with the standard twentysixteen Theme, but without Divi.

I am creating a layout for the standard posts of WordPress, just to use additional fields for a better Control of the content.

The Problem now is,..

I always see the original WordPress Post and additionally the Layout I am creating, together!!! Please have look on the screenshot

How can reduce it to my layout only? What is my mistake?

All the best from Germany

Jörg

#620476

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Hi Jörg

When you create a template with either Layouts or Views it only replaces the part of the content that is generated by the_content() function in the theme files (literally the part where the theme would output the post body).

The theme will typically output the post title, perhaps some meta info (such as author, post date), and Toolset doesn't control that.

(With some themes we have added an integration layer so that if the theme provides options for disabling such content you can set those options in your template, but twentysixteen is not covered by this.)

So you can either accept that the theme outputs such texts as the title and be sure to not include the same in your template so that they are not duplicated.

Or you can edit the theme files to remove them.

Or rather, make a copy of the theme file in question and rename it so that it applies to your custom post type (i.e. duplicate single.php and name the copy single-my-post-type.php) and then edit that template file to remove the parts you do not want to appear.

#620512

Hi There Nigel,

Ok, I understood. And Thanks for your soon reply.

But I do have content written in the existing post editor. How can I replace it with a view or layout if I want the output of it
( The Content uses the standard editor field of WordPress ) .

I surely want to have my own Post Title and meta and additional my own extra fields.

I am confused 🙁

Jörg

#620580

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Screen Shot 2018-02-28 at 14.42.28.png

Sorry if I wasn't clear.

In my screenshot of a single post displayed using a Layout with twentysixteen the area that is output by the Layout is marked in red, the rest of the content is output by the theme.

You have full control over what appears inside the red box using the templates you create with Toolset, but to modify the areas outside the red box would require editing the theme files.

Twentysixteen uses the file single.php for all single posts (but would be displaced by a more specific file such as single-project.php to display a single project post).

That file looks like this:

/**
 * The template for displaying all single posts and attachments
 *
 * @package WordPress
 * @subpackage Twenty_Sixteen
 * @since Twenty Sixteen 1.0
 */

get_header(); ?>

<div id="primary" class="content-area">
	<main id="main" class="site-main" role="main">
		<?php
		// Start the loop.
		while ( have_posts() ) : the_post();

			// Include the single post content template.
			get_template_part( 'template-parts/content', 'single' );

			// If comments are open or we have at least one comment, load up the comment template.
			if ( comments_open() || get_comments_number() ) {
				comments_template();
			}

			if ( is_singular( 'attachment' ) ) {
				// Parent post navigation.
				the_post_navigation( array(
					'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ),
				) );
			} elseif ( is_singular( 'post' ) ) {
				// Previous/next post navigation.
				the_post_navigation( array(
					'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentysixteen' ) . '</span> ' .
						'<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' .
						'<span class="post-title">%title</span>',
					'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentysixteen' ) . '</span> ' .
						'<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' .
						'<span class="post-title">%title</span>',
				) );
			}

			// End of the loop.
		endwhile;
		?>

	</main><!-- .site-main -->

	<?php get_sidebar( 'content-bottom' ); ?>

</div><!-- .content-area -->

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

Note that single.php doesn't output the_content() directly, it uses a template part "content-single.php" to show the post content.

That file looks like this:

/**
 * The template part for displaying single posts
 *
 * @package WordPress
 * @subpackage Twenty_Sixteen
 * @since Twenty Sixteen 1.0
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<header class="entry-header">
		<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
	</header><!-- .entry-header -->

	<?php twentysixteen_excerpt(); ?>

	<?php twentysixteen_post_thumbnail(); ?>

	<div class="entry-content">
		<?php
			the_content();

			wp_link_pages( array(
				'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
				'after'       => '</div>',
				'link_before' => '<span>',
				'link_after'  => '</span>',
				'pagelink'    => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
				'separator'   => '<span class="screen-reader-text">, </span>',
			) );

			if ( '' !== get_the_author_meta( 'description' ) ) {
				get_template_part( 'template-parts/biography' );
			}
		?>
	</div><!-- .entry-content -->

	<footer class="entry-footer">
		<?php twentysixteen_entry_meta(); ?>
		<?php
			edit_post_link(
				sprintf(
					/* translators: %s: Name of current post */
					__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
					get_the_title()
				),
				'<span class="edit-link">',
				'</span>'
			);
		?>
	</footer><!-- .entry-footer -->
</article><!-- #post-## -->

Here we see the_content(), which will output the content of your Toolset template (whether you create a Template Layout or use a Views Content Template), as well as the rest of the content that the theme outputs for single posts, including the post title, post excerpt, featured image, navigation links, author bio, post meta etc.

If you don't want any of that to be shown you would need to edit the theme files.

In my screenshot the title appears twice because the theme generates the title and then my Layout also outputs the title (because I created the Layout to show the post title, then the post content).

Is that clear?

If you need help editing the theme files then please let me know specifically what you would like to do.

#621255

Hi Nigel,

I love your detailed answers and it helps me a lot. Thanks for that.

I do understand how it works, yes. But unfortunately I am not able to identify the Post Title and the meta informations in the php code yet ,... just to out comment it ( with /* */.

My single.php looks like this:

<?php
/**
* The template for displaying all single posts and attachments
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/

get_header(); ?>

<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();

// Include the single post content template.
get_template_part( 'template-parts/content', 'single' );

// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}

if ( is_singular( 'attachment' ) ) {
// Parent post navigation.
the_post_navigation( array(
'prev_text' => _x( '<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'twentysixteen' ),
) );
} elseif ( is_singular( 'post' ) ) {
// Previous/next post navigation.
the_post_navigation( array(
'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentysixteen' ) . '</span> ' .
'<span class="screen-reader-text">' . __( 'Next post:', 'twentysixteen' ) . '</span> ' .
'<span class="post-title">%title</span>',
'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentysixteen' ) . '</span> ' .
'<span class="screen-reader-text">' . __( 'Previous post:', 'twentysixteen' ) . '</span> ' .
'<span class="post-title">%title</span>',
) );
}

// End of the loop.
endwhile;
?>

</main><!-- .site-main -->

<?php get_sidebar( 'content-bottom' ); ?>

</div><!-- .content-area -->

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

And my content single.php:

<?php
/**
* The template part for displaying single posts
*
* @package WordPress
* @subpackage Twenty_Sixteen
* @since Twenty Sixteen 1.0
*/
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->

<?php twentysixteen_excerpt(); ?>

<?php twentysixteen_post_thumbnail(); ?>

<div class="entry-content">
<?php
the_content();

wp_link_pages( array(
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
'separator' => '<span class="screen-reader-text">, </span>',
) );

if ( '' !== get_the_author_meta( 'description' ) ) {
get_template_part( 'template-parts/biography' );
}
?>
</div><!-- .entry-content -->

<footer class="entry-footer">
<?php twentysixteen_entry_meta(); ?>
<?php
edit_post_link(
sprintf(
/* translators: %s: Name of current post */
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
get_the_title()
),
'<span class="edit-link">',
'</span>'
);
?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->

I am not a coder ,... but I thought I can read php,... 🙁

But maybe with a little help of you It should work.

Jörg

#621359

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Hi Jörg

I think the content you want to remove is mostly found in the second file, template-parts/content-single.php.

Here I have commented out most of that file except for the content itself and the html elements that help structure the page.

If you find something has gone that you still want you should be able to work out what to re-instate.

<?php
/**
 * The template part for displaying single posts
 *
 * @package WordPress
 * @subpackage Twenty_Sixteen
 * @since Twenty Sixteen 1.0
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<?php 
/**
	<header class="entry-header">
		<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
	</header><!-- .entry-header -->

	<?php twentysixteen_excerpt(); ?>

	<?php twentysixteen_post_thumbnail(); ?>
*/ 
?>
	<div class="entry-content">
		<?php
			the_content();

/**
			wp_link_pages( array(
				'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
				'after'       => '</div>',
				'link_before' => '<span>',
				'link_after'  => '</span>',
				'pagelink'    => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
				'separator'   => '<span class="screen-reader-text">, </span>',
			) );

			if ( '' !== get_the_author_meta( 'description' ) ) {
				get_template_part( 'template-parts/biography' );
			}
*/
		?>
	</div><!-- .entry-content -->

<?php
/**
	<footer class="entry-footer">
		<?php twentysixteen_entry_meta(); ?>
		<?php
			edit_post_link(
				sprintf(
					// translators: %s: Name of current post
					__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
					get_the_title()
				),
				'<span class="edit-link">',
				'</span>'
			);
		?>
	</footer><!-- .entry-footer -->
*/
?>
</article><!-- #post-## -->
#625256

No more help needed in this case