Wordpress page.php source code - wordpress

<div class="row clearfix">
<div class="content-wrap ninecol clearfix">
<div class="content">
<h1 class="title">Om oss</h1>
<hr>
<div class="entry-content">
<h4>Vilka är Unified Sweden?</h4>
<p>Unified Sweden är en webbyrå som ständigt strävar </p>
</div>
<div>
</div>
if I would want to make this as a template so that I can use it for other pages is the code below right?
<div class="content-wrap ninecol clearfix">
<div class="row clearfix">
<div class="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
<div>
</div>

You should have a look at the Wordpress Template hierarchy and Page Templates.
You should create a file called page-<something-you-want>.php. Open the file and add a template name to it and add your content.
For example:
<?php
/*
* Template Name: A Static Page
*/
get_header(); ?>
<whatever content you want to add>
<?php get_footer(); ?>
Then go to Add new Page, and in the Page Attribute box, you'll see a dropdown called Template. You select the template called A Static Page (or otherwise defined above) and publish the page. That's all.
To get the content
To get the content in Wordpress, you need to The Loop
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content(); // displays whatever you wrote in the wordpress editor
endwhile; endif; //ends the loop
?>
Getting back to your case:
<div class="sevencol">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div>
<?php the_content(); ?>
</div>
<?php endwhile; endif; ?>
</div>

Related

Wordpress hierarchy issue with categorized post not using specific template

I'm trying to implement a dedicated template for any post with a category slug of 'rentals'. There are posts in the database with a category of rentals set up and applied. I've created the template with a standard loop and called it category-rentals.php, saving it in my root folder.
It's just not working. It keeps reverting to single post template (index.php specifically).
My rendered body classes are as such:
post-template-default single single-post postid-278 single-format-standard
Am I missing a step here?
category-rentals.php:
/*
* Rental property template
*/
?>
<?php get_header(); ?>
<div class="jumbotron jumbotron-fluid" style="background-image: url('<?php bloginfo( 'template_url' ); ?>/img/bg-semi-trans.png'), url('<?php bloginfo( 'template_url' ); ?>/img/bg-jumbotron.jpg');">
<div class="container">
<div class="headline text-center animated fadeInUp">
<p><?php wp_title(''); ?></p>
</div>
</div>
</div>
<section>
<div class="container">
<div class="row">
<div class="col-12">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else : ?>
<p><?php esc_html_e( 'Sorry, no content matched your criteria.' ); ?></p>
<?php endif; ?>
<hr>
← Go Back | Contact Us
</div>
</div>
</div>
</section>
<?php get_footer(); ?>

How To Integrate Woocommerce With A Custom Wordpress Theme

I am having a hard time figuring out where to add the woocommerce loop in my woocommerce.php file.
Here is the page.php code,
<?php
/*
Package: OnAir2
Description: Normal single page template with sidebar
Version: 0.0.0
Author: QantumThemes
Author URI: http://qantumthemes.com
*/
?>
<?php get_header(); ?>
<?php
get_template_part ('phpincludes/menu');
get_template_part ('phpincludes/part-searchbar');
?>
<div id="maincontent" class="qt-main">
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- ======================= HEADER SECTION ======================= -->
<?php get_template_part( 'phpincludes/part-header-caption-page'); ?>
<!-- ======================= CONTENT SECTION ======================= -->
<div class="qt-container qt-spacer-l">
<div class="row">
<div class="col s12 m12 l1 qt-pushpin-container">
<div class="qt-pushpin">
<?php get_template_part( 'phpincludes/sharepage' ); ?>
</div>
<hr class="qt-spacer-m">
</div>
<div class="col s12 m12 l8">
<div class="qt-the-content">
<?php the_content(); ?>
</div>
<?php if ( comments_open() || '0' != get_comments_number() ){ ?>
<hr class="qt-spacer-m">
<?php comments_template(); ?>
<?php } ?>
<hr class="qt-spacer-l">
</div>
<div class="qt-sidebar col s12 m12 l3">
<?php get_template_part ( 'phpincludes/sidebar' ); ?>
<hr class="qt-spacer-l">
</div>
</div>
</div>
</div>
<?php endwhile; // end of the loop. ?>
<?php get_template_part ( 'phpincludes/part-sponsors' ); ?>
</div><!-- .qt-main end -->
<?php get_template_part ( 'phpincludes/footerwidgets' ); ?>
<?php get_template_part ( 'phpincludes/part-player-sidebar' ); ?>
<?php get_footer(); ?>
Where do I add the
<?php woocommerce_content(); ?>
I have tried just using the the get header and footer alone but the output was very very bad. Since the developer didn't make the theme woocommerce compatible I need to make it....
Replace the_content(); with woocommerce_content();. But still it won't adopt design. You manually have to make it woocommerce compatible.

How to print text from db in special template for specific page in wordpress

I have five pages and I have created a different layout for last two pages, that layout has a div with class infoDiv and that div has a text which I just put manually in the source code, so I can't change it through wordpress. How can I have it available in my dashboard so client no need to change in code?
<?php
/*
Template Name: Special Layout
*/
get_header();
if (have_posts()) {
while (have_posts()) {
the_post();
?>
<article class="borderClass">
<h2> <?php the_title(); ?> </h2>
<div class="infoDiv">
<h4>This is info div</h4>
<p>this is the text I want to edit or add
using dashboard.</p>
</div>
<?php the_content(); ?>
</article>
<?php
}
} else {
echo "<p>No content found</p>";
}
get_footer();
Just move <?php the_content(); ?> like below
<article class="borderClass">
<?php the_title( '<h2>', '</h2>' ); ?>
<div class="infoDiv">
<?php the_content(); ?> <!-- Entered content -->
</div>
</article>

Loading wordpress posts after user clicks anchor

This is my tab menu, where user can select tab
<div id="slider-menu" class="row">
<div class="span12">
<ul class="nav nav-tabs" id="myTab">
<li class="active">Latest events<div class="triangle"></div></li>
<li>Our champions</li>
<li>We have puppies!</li>
</ul>
</div>
</div>
And there are my tabs, in which content is loaded when page loads
<div class="tab-content">
<div class="tab-pane active" id="home">
<img src="<?php bloginfo('template_url'); ?>/img/slider.png" />
<div class="span12">
<?php
query_posts('cat=7');
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
</div>
<div class="tab-pane" id="profile">
<img src="<?php bloginfo('template_url'); ?>/img/slider.png" />
<div class="span12">
<?php
query_posts('cat=8');
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
</div>
<div class="tab-pane" id="messages">
<img src="<?php bloginfo('template_url'); ?>/img/slider.png" />
<div class="span12">
<?php
query_posts('cat=9');
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
</div>
</div>
When there will be a lot of posts, it will take page to load too long, so my basic idea is to load all posts to the first tab when page loads, and load posts to another tab when user selects it.
I struggle how to combine wp posts loop and ajax to load posts when user clicks specific tab.
Thank you for your help in advance.
$.ajaxSetup({cache:false});
$('#myTab li').click(function(){
var cat_id = $(this).children().attr('rel');
$.get('location.href' + cat_id, function(data) {
$('#' + cat_id).html(data);
return false;
});
So I output category id to anchor rel attribute, then I add click event handler in which I call .get function. After all, I output data.

Wordpress: Post has no formatting

I've just begun learning to develop WordPress themes, and I'm developing my first theme, but I have an issue, where the formatting set in the Visual Editor isn't used when displaying a post...
So, my code is as follows:
<?php
/*
Template Name: News
*/
?>
<?php get_header(); ?>
<div id="contentWrap">
<div id="content">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = array (
'posts_per_page' => 3,
'paged' => $paged,
'cat' => 4
);
query_posts ($query); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<article <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="meta">
<em>Posted on:</em> <?php the_time('F jS, Y') ?>
</div>
<div class="entry">
<?php the_content(); ?>
</div>
</article>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php else : ?>
<h2>Not found</h2>
<?php endif; ?>
</div><!-- end content -->
</div><!-- end contentWrap -->
<?php get_footer(); ?>
So the issue is, if I create a post and set some formatting (bold, italics, etc.), the post is still shown as plain text with no formatting except line breaks... I'm guessing the issue is related to how I get the post, but as I'm completely new in WordPress, I haven't been able to find the solution...
What am I missing?

Resources