Create page from a template with customized body - wordpress

Created a page template named page-person.php
<?php
/**
* Template Name: Person Page
* 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 may use a
* different template.
*
* #link https://codex.wordpress.org/Template_Hierarchy
*
* #package mentorme
*/
get_header(); ?>
<div class="personality">
<!-- dynamic content -->
<?php the_content(); ?>
</div>
<?php get_footer(); ?>
Now I have added some test content, while creating the page from Template 'Person Page' like this
but on page /dr-xyz its not showing text 'Testing' anywhere!

You could use the_content to display your content and the_title() to display your post title. Try the following code
<?php get_header(); ?>
<div class="personality">
<?php if (have_posts()) :
while (have_posts()) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php get_footer(); ?>

Try this
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
the_content();
} // end while
} // end if

Related

Change Woocommerce pagination permalinks

My Woocommerce Shop uses pretty permalinks but I want to disable it for pagination.
When I visit a Category page and manually add the parameter „?paged=2“ for example the page does not redirect me to the permalink version.
But as of now the links are generated like „/page/2“.
How can I achieve that the parameter version is used on the Category page instead of „/page/2“?
Code for the Archive Pages:
<?php
get_header();
do_action( 'shoptimizer_page_start' );
?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php while ( have_posts() ) : the_post();
do_action( 'shoptimizer_page_before' );
get_template_part( 'content', 'page' );
/**
* Functions hooked in to shoptimizer_page_after action
*
* #hooked shoptimizer_display_comments - 10
*/
do_action( 'shoptimizer_page_after' );
endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div><!-- #secondary -->
<?php
get_footer();
Are you editing via actual PHP? If so, I'd recommend woo_pagination to control that.
Woo_pagination documenation

wordpress theme page not showing plugin gallery

I am new to Wordpress. I am trying to build a theme from scratch.
I created the page.php which is the following:
<?php
/**
* The template for displaying 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 nameofpackage
*/
get_header(); ?>
<?php get_footer(); ?>
I also installed the NextGen plugin.
I created a new page, and use the "add Gallery" button of NextGen; i ended up with
[ngg src="galleries" ids="1" display="basic_thumbnail"]
inside the text section of the page (the visual section shows the plugin logo in a box).
When i tried to preview the result i only get the header and the footer with nothing in the middle; the inspector shows no presence of the code related to the gallery.
If i try the same thing with ThemeFifteen it works.
So my question is: is there something i need to include in the function.php that allows my theme to include the output of the plugin in the page? thx
You're missing the WP loop and the_content(), so its absolutely normal to not see anything between the header and the footer. You need something like this for example:
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'loop-templates/content', 'page' );//calling the folder with your loop templates ?>
<?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. ?>
And inside your loop template something like :
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?>
<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'understrap' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php edit_post_link( __( 'Edit', 'understrap' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->
This is very common way to structure your theme, but please spend some time on beginners tutorials about developing custom themes. It's very easy to get the basic concepts, you'll need couple of hours to get the idea ! This is just an example I want to stress on that, quick and dirty fix of your code would be:
<?php
/**
* The template for displaying 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 nameofpackage
*/
get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; // end of the loop. ?>
<?php get_footer(); ?>
What you're looking for is do_shortcode() See the docs
Make sure to echo it as well.
<?php
get_header();
echo do_shortcode('[ngg src="galleries" ids="1" display="basic_thumbnail"]');
get_footer();
You could also use apply_filters() and pass in the 'the_content' hook. That would render your shortcode with the same hooks/filters as used br the wysiwyg editor in the back-end but ultimately it's just using do_shortcode() behind the scenes.
<?php
get_header();
echo apply_filters('the_content', '[ngg src="galleries" ids="1" display="basic_thumbnail"]');
get_footer();

Why content in my page can't display?

I edit a new page, here is the content.
Publish and view it.
Why is nothing displayed?
The theme is "twentyfourteen".
sudo cat /var/www/html/wp/wp-content/themes/twentyfourteen-child/page.php
<?php /* Template Name: Custom Front Page */ ?>
<?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 WordPress
* #subpackage Twenty_Fourteen
* #since Twenty Fourteen 1.0
*/
get_header(); ?>
<div id=”main-content” class=”main-content”>
<div id=”primary” class=”content-area”>
<div id=”content” class=”site-content” role=”main”>
<p>it is a test</p>
</div><!– #content –>
</div><!– #primary –>
<?php get_sidebar( ‘content’ ); ?>
</div><!– #main-content –>
<?php
Why are all the double quotation marks ” instead of ", and single quotation marks are ‘ instead of '?
How do I get my page to display?
Are the quotation marks in the right format?
You don't print the content on the site. The best way do to this is to do it with the WordPress loop. So the code should look something like this:
<?php </* Template Name: Custom Front Page */ ?>
<?php get_header(); ?>
<div id="main-content" class="main-content">
<div id=”primary” class=”content-area”>
<div id="content" class="site-content" role="main">
<?php if(have_posts): while(have_posts): the_post(); ?>
<h1><?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
</div>
<?php get_sidebar( 'content' ); ?>
</div>
<?php get_footer(); ?>
No it should be " and '

Co-Authors Plus Wordpress Plugin - List all the authors for same post

I want to display name of multiple authors on the front end like below
By John Doe,Linn Doe and Penny
In the back end I can add many users for the same post.But In the front end only the first author on the post shows up both for the byline and the bio. I'm using Twenty Thirteen theme and how to show all the user added in the back end in the front end?
this is my single.php file
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php twentythirteen_post_nav(); ?>
<?php comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Incorporate Co-Authors Plus template tags into your theme
Other Solution:
In order to add add Co-Authors Plus support you must have access to edit the theme template. In order to display information about multiple authors on the fronted, you'll need to add the necessary Co-Authors Plus template tags to your single.php and other theme files.
Specifically for the bylines, you'll want to replace where it says something like:
<?php the_author(); ?>
With something like this:
<?php if ( function_exists( 'coauthors' ) ) { coauthors(); } else { the_author(); } ?>
That specific snippet will allow your theme to degrade gracefully when Co-Authors Plus isn't activated.
To show the authors with their posts link, you'll want to use something like:
<?php if ( function_exists( 'coauthors_posts_links' ) ) { coauthors_posts_links(); } else { the_author_posts_link(); } ?>
You can use the following code for the bios
<?php $coauthors = get_coauthors(); ?>
<?php foreach( $coauthors as $coauthor ): ?>
<center><div class="authbio">
<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $coauthor->user_firstname; ?>.jpg" alt="" class="alignleft"/>
<?php $userdata = get_userdata( $coauthor->ID ); ?>
<?php if ( $userdata->user_description ) echo $userdata->user_description; ?>
</div></center>
<?php endforeach; ?>
Reference

How to add sidebar at single.php in Wordpress

I'm having a problem when it comes to adding sidebar at single.php. I already included
<?php get_sidebar(); ?>
But it seems to be appear below and the content(Blog post) still at the middle of the whole page. I've tried to check all of the previous forum but none of them helped me to figure this out.
Here's my single.php
<?php
/**
* The template for displaying all single posts.
*
* #package Tesseract
*/
get_header(); ?>
<div id="primary" class="full-width-page">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'single' ); ?>
<?php tesseract_post_nav(); ?>
<?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 comments_template(); ?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
The most logical reason for this to happen is that there isn't enough room for both the main content and the sidebar to appear next to each other. Check the width of your sections in your stylesheet and make the necessary changes to the styles.
First of all you create the sidebar in the admin and then call that sidebar where you want.Following is the code for calling sidebar
<ul id="sidebar">
<?php dynamic_sidebar( 'right-sidebar' ); ?>
Use following link to know more about how to create a sidebar
https://codex.wordpress.org/Function_Reference/register_sidebar

Resources