Single page WordPress theme - php

I made a single page HTML to WordPress website. There are 4 sections and 4 menu items. The section id and menu id are the same (ordering by page order).
Basically in the HTML format when you click on the menu, the scroll bar automatically goes to the related section. When I turn it into WordPress everything is working but when I click over the menu it doesn't.
<!-- Menu section -->
<div class="col-md-8 col-sm-10 col-xs-4 main-menu text-right">
<ul class="menu-first hidden-sm hidden-xs">
<?php
global $post;
$args = array('post_type'=>'page','orderby'=>'menu_order','order'=>'ASC');
$myposts = get_posts($args);
foreach($myposts as $post) : setup_postdata($post);?>
<li><?php the_title(); ?></li>
<?php endforeach; ?>
</ul>
<i class="fa fa-bars"></i>
</div> <!-- /.main-menu -->
<!-- Service -->
<div class="content-section" id="<?php echo $post->post_name; ?>">
<div class="container">
<div class="row">
<div class="heading-section col-md-12 text-center">
<h2>Services</h2>
</div> <!-- /.heading-section -->
</div> <!-- /.row -->
<div class="row">
<?php
global $post;
$args = array('post_type'=>'service','orderby'=>'menu_order','order'=>'ASC');
$myposts = get_posts($args);
foreach($myposts as $post) : setup_postdata($post); ?>
<div class="col-md-3 col-sm-6">
<div class="service-item" id="service-1">
<div class="service-icon">
<i class="fa fa-<?php echo $service_icon; ?>"></i>
</div> <!-- /.service-icon -->
<div class="service-content">
<div class="inner-service">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
</div>
</div> <!-- /.service-content -->
</div> <!-- /#service-1 -->
</div> <!-- /.col-md-3 -->
<?php endforeach; ?>
</div> <!-- /.row -->
</div> <!-- /.container -->
</div> <!-- /#services -->
Related code located also at paste bin.

I don't see any anchors with name attributes for your link to actually jump to. Try this:
<?php foreach($myposts as $post) : setup_postdata($post); ?>
<div class="col-md-3 col-sm-6">
<div class="service-item" id="service-1">
<!-- Rest of markup removed for clarity -->
<h3>
<a name="<?php echo $post->post_name; ?>"><?php the_title(); ?></a>
</h3>
</div>
</div>
<?php endforeach; ?>

Related

Wordpress loop doesn't work

I created my own template in WordPress, but the loop entries does not work. I would like to entries work on one of the subpages. I also added entries.
This is my code of my subpage. Please help me. I don't know what is wrong. I added a picture under the code.
<?php include 'header.php'; ?>
<main class="subpage-blog">
<div class="subpage-banner">
<div class="container">
<h3>BLOG SIDEBAR</h3>
<div class="breadcrumbs">
</div>
</div>
</div>
<aside class="side-menu col-md-4">
<div class="search">
<h4>Search blog</h4>
<input type="text" value="Search">
</div>
<!-- .search -->
<div class="categories">
<h4>Blog Categories</h4>
<ul class="categories-blog-ul">
<li>Inspirtation</li>
<li>Work</li>
<li>Tech</li>
<li>Creative</li>
</ul>
</div>
<!--.categories-->
<div class="recent-posts">
<h4>Recents posts</h4>
<ul>
</ul>
</div>
<!-- .recent-posts-->
<div class="tags-spot">
<h4>Tags</h4>
<div class="tag"></div>
</div>
<!-- .tags-spot-->
</aside>
<!-- .side-menu-->
<article class="content">
<div class="container">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="news-box">
<div class="news-list-content">
<a href="">
<h3><?php the_title(); ?></h3>
<?php the_content('czytaj dalej'); ?>
</a>
</div>
<!-- .news-list-content-->
<div class="image-box-news">
<img src="<?=get_template_directory_uri(); ?>/images/ikona-wpisu.png" alt="" />
</div>
</div>
<!-- .news-box-->
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
<!-- .container-->
</article>
<!-- .content-->
</main>
<?php include 'footer.php'; ?>
The problem is that:
if (have_posts()) : while (have_posts()) : the_post();
is using the current page's have_posts query.. That means that it probably will just show whatever that current page template's content would be.
Instead, you'll want to create an entirely new query object and call these functions on it like so:
<?php
$the_query = new WP_Query( array('posts_per_page' => 10 ) ); //Create our new custom query
if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="news-box">
<div class="news-list-content">
<h3><?php the_title(); ?></h3>
<?php the_content('czytaj dalej'); ?>
</div>
<!-- all your other markup goes here.... -->
</div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php wp_reset_postdata(); //Restore the original postdata for this page, if needed later ?>

Why some custom fields in a section of my WordPress website aren't working?

I'm building a WordPress website. Everything went fine before using custom post types. When I use CPT and write PHP code then a section can't print the custom fields. This affects only one section. Other sections and custom fields works fine.
Before adding this code the custom field worked fine:
<?php
$args = array("post_type" => "project_feature");
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-sm-4">
<?php
if(has_post_thumbnail())
{
the_post_thumbnail();
}
?>
<h3><?php the_title(); ?></h3>
<div class="black_text"><?php the_content(); ?></div>
</div> <!-- col -->
<?php endwhile; wp_reset_query(); ?>
But now if I delete this code my custom feature still doesn't work. I don't understand what I am doing wrong. I still don't know if it's my code or something else in WordPress.
This custom fields within the instructor section aren't working:
<?php
// instructor custom fields
$instructor_name = get_field('instructor_name');
$instructor_description = get_field('instructor_description');
$students = get_field('students');
$views = get_field('views');
$courses = get_field('courses');
?>
<!-- INSTRUCTOR
=========================================
-->
<section id="instructor">
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="row">
<div class="col-sm-8">
<h3>Your Instructor <small><?php echo $instructor_name; ?></small></h3>
</div> <!-- col -->
<div class="col-sm-4">
<ul>
<li>
<i class="fa fa-facebook social" aria-hidden="true"></i>
</li>
<li>
<i class="fa fa-google-plus social" aria-hidden="true"></i>
</li>
<li>
<i class="fa fa-linkedin social" aria-hidden="true"></i>
</li>
</ul>
</div> <!-- col -->
</div> <!-- row -->
<div class="row">
<div class="col-sm-12">
<p class="black_text"><?php echo $instructor_description; ?></p>
<hr>
</div> <!-- col -->
</div> <!-- row -->
<div class="row">
<div class="col-sm-12">
<h3>The numbers <small>They don't lie...</small></h3>
</div> <!-- col -->
<div class="col-sm-4 round_display">
<p class="black_text"><?php echo $students; ?> students</p>
</div> <!-- col -->
<div class="col-sm-4 round_display">
<p class="black_text"><?php echo $views; ?> views</p>
</div> <!-- col -->
<div class="col-sm-4 round_display">
<p class="black_text"><?php echo $courses; ?> courses</p>
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- col -->
<div class="col-sm-6">
<img src="<?php bloginfo('stylesheet_directory'); ?>/image/brad.png" alt="man" class="img-responsive center-block income_image"/>
</div> <!-- col -->
</div> <!-- row -->
</div> <!-- container -->
</section> <!-- INSTRUCTOR -->

the_field in wordpress not outputting in html depending on the order of pages

I have something that I just can't understand. I did a one page layout site in wordpress. It consist of one template-index.php that only have one mainContainer div and about 6 include_once template-. Then in the admin section of wordpress I used advanced custom fields to create the different fields all related to template-index.php.
Everything shows up just fine except for the text on the last frame or last include if you will. But here is the strange thing. If I change the order of the last two includes both text shows up just fine and then when I change the order back the last include loose it's text again.
I checked the code, every php tag is closed just fine, the include before also. I don't know. Did something like this ever happen to one of you? What could it be?
Thanks
edit:
here is a bit of code.
So the index page is pretty simple:
<?php
/* Template Name: index template */
?>
<?php get_header(); ?>
<div class="mainContainer"id='fullpage'>
<?php include_once 'template-about.php'; ?>
<?php include_once 'template-theDesign.php'; ?>
<?php include_once 'template-theApp.php'; ?>
<?php include_once 'template-getApp.php'; ?>
<?php include_once 'template-community.php'; ?>
<?php include_once 'template-contact.php'; ?>
</div>
<?php get_footer(); ?>enter code here
the last two includes look like this:
<?php
/* Template Name: Bob community template */
?>
<!-- <div id="section-5"> -->
<div class="sectionContainer community section" id='section_five'>
<div class="container main">
<div class="vertical100 firstSection col-md-12 topSection ">
<section class='worldMap animation col-md-6'>
<div class="imgContainer">
<div class="wordpressImg">
<img class='worldMap' src="<?php echo get_template_directory_uri(); ?>/img/worldmap.png" />
</div> <!-- wordpressImg -->
</div><!-- imgContainer -->
</section>
<section class="explications col-md-6">
<div class="communityExplication">
<div class="wordpressTexte">
<?php the_field('community_text'); ?>
<div class="stories">
<?php
$args = array( 'post_type' => 'stories', 'posts_per_page' => 8, 'orderby' => 'rand' );
$loop = new WP_Query($args);
$posts = $loop->posts;
if(have_posts()) {
$first = true; ?>
<div class="storieAligner">
<div class="stories-container ">
<?php
$count = 0;
while($loop->have_posts() ) : $loop->the_post();
$randomPost = $posts[$count];
$image = get_field('images');
$temoignage = get_field('temoignage');
?>
<!-- <div class="storiePhoto"> -->
<div class='storiesThumbs' style='background-image: url("<?php echo $image['url']; ?>")' data-temoignage="<?php echo $temoignage; ?>"></div>
<div class="categorie"></div>
<!-- </div> -->
<?php $count++; endwhile; ?>
</div> <!-- stories-container -->
<div class="fullStorie hiddenStorie">
<div class="back"></div>
<div class="leftDiv">
<div class="leftContent">
</div>
</div>
<div class="rightDiv">
<div class="rightContent"></div>
</div>
</div>
</div> <!-- storieAligner -->
<?php }; ?> <!-- if have_posts -->
</div> <!-- stories -->
<div class="linkContainer" ><a class='formToggle pinkButton roll' href="#" title="Wha you say"><span data-title='What you say'>What you say</span></a></div>
</div> <!-- wordpressTexte -->
</div> <!-- commnunityExplication -->
<!-- <div class="storiesFormContainer"> -->
<div class="storiesForm hidden">
<div class="formContainer">
<h1><?php echo __('Leave a Review of your app ', 'site'); ?></h1>
<?php echo do_shortcode('[contact-form-7 id="89" title="community-contact"]'); ?>
</div>
</div>
<!-- </div> storiesFormContainer -->
</section>
</div> <!-- get app -->
</div> <!-- main -->
and the contact template like this
<?php
/* Template Name: Contact-us template */
?>
<!-- section-6 -->
<div class="sectionContainer contact section" id='section_six'>
<div class="container main" >
<div class="vertical100 col-md-12 topSection ">
<section class='explications col-md-3'>
<div class="blockTexte">
<div class="wordpressTexte">
<?php the_field('questions'); ?>
<a class ='pinkButton roll' href="#" title="visit page"><span data-title='<?php echo __('visit page', 'site'); ?>'><?php echo __('visit page', 'site'); ?></span></a>
</div>
</div>
</section>
<section class="formulaire col-md-9">
<div class="formContainer">
<div class="wordpressForm">
<?php echo do_shortcode('[contact-form-7 id="44" title="contact-us"]'); ?>
</div>
</div>
</section>
</div> <!-- knowBob -->
</div>
So what could be wrong?
P.s. I know there's a bit a french and english in the code. I usually write what comes up first in my head.
You need to reset the post data to the original query using wp_reset_postdata after you're done looping through a custom query:
<div class="stories-container ">
<?php
$count = 0;
while($loop->have_posts() ) : $loop->the_post();
$randomPost = $posts[$count];
$image = get_field('images');
$temoignage = get_field('temoignage');
?>
<!-- <div class="storiePhoto"> -->
<div class='storiesThumbs' style='background-image: url("<?php echo $image['url']; ?>")' data-temoignage="<?php echo $temoignage; ?>"></div>
<div class="categorie"></div>
<!-- </div> -->
<?php $count++; endwhile; wp_reset_postdata(); ?><!-- this line here -->
</div> <!-- stories-container -->
Otherwise the $post object will remain the last post of the $loop query, causing any other behind the scenes requests for post data down the road (in your case get_field) to reference the wrong post until you hit the outer loop again.

im trying to remove the double post image

when you go to:
http://dageniusmarketer.com/
you will see the posts have 2 images. I'm trying to remove the one on the bottom.
I initially added
<?php the_post_thumbnail( $size, $attr ); ?>
for the main post image, as I wasn't getting the placement I wanted, which was ABOVE the post statistics. Now that I have it above the statistics, I still have the original image, and I want to remove it.
I'm trying to play with the class .wp-image,
but that isn't giving me any sort of luck. I just want to remove the 2nd duplicate image underneath the statistics and keep whatever other images I may wish to write into my post body in the future. How do I do this?
edit: here is my php code:
<?php get_header(); ?>
<div id="main">
<div id="content">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- item -->
<div class="item entry" id="post-<?php the_ID(); ?>">
<div class="itemhead">
<h1>
<?php the_title(); ?>
</h1>
<?php the_post_thumbnail( $size, $attr ); ?>
<div class="postStatsContainer">
<div class="postViews">100 Views</div>
<div class="slash"></div>
<div class="postShares">100 Shares</div>
<div class="slash"></div>
<div class="postComments">100 Comments</div>
<div class="slash"></div>
<div class="date"><?php the_time('M jS, Y') ?></div>
</div>
<div style="clear: both"></div>
<!--<div class="readMore_Container">-->
<?php the_content('Read More »'); ?>
<div class="postCounter">
<i class="fa fa-pencil-square-o fa-2x"></i>#200
</div>
<div class="metadata" style="clear:both;">
<div class="TagIcon"></div>
Filed under
<span class="category"><?php the_category(', ') ?></span> |
<?php edit_post_link('Edit', '', ' | '); ?>
<?php comments_popup_link('Comment (0)', ' Comment (1)', 'Comments (%)'); ?>
</div>
<div style="clear:both;"></div>
<div style="clear:both;"></div>
</div>
</div>
<!-- end item -->
<?php comments_template(); // Get wp-comments.php template ?>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Previous Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Next Entries »') ?></div>
<p> </p>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
<!-- end content -->
</div>
<div id="primary">
<?php include(TEMPLATEPATH."/l_sidebar.php");?>
</div>
<div id="secondary">
<?php include(TEMPLATEPATH."/r_sidebar.php");?>
</div>
<?php get_footer(); ?>

PHP - Wordpress post loop not showing

I'm having trouble with the Blog portion of my project I'm working on. I have made a new template and pointed the Blog page to that template but no posts show up on the page. I have also went under Reading > and changed the Posts Page to Blog, the whole page doesn't show up. Below is the code and a link:
http://www.hbaofwashingtoncounty.org/hbawc2014/blog/
<?php
/*
Template Name: Blog
*/
;?>
<?php get_header();?>
<div class="inner">
<!-- Content Section Start -->
<div class="contentsec-new twocol">
<!-- Top Header Start -->
<div class="topheader">
<div class="inner">
<!-- Logo Start -->
<div class="logo">
<a href="<?php echo home_url();?>">
<?php if($logo_img = $_extracoding->set_value('LOGO', get_template_directory_uri().'/images/logo.png', true)): ?>
<img src="<?php echo $logo_img;?>" alt="<?php bloginfo('name');?>" id="logo" />
<?php else:?>
<span class="logo"> </span>
<?php endif;?>
</a>
</div>
<!-- Logo End -->
<!-- Right Header Start -->
<div class="righthead">
<div class="topsec">
<!-- Service Time and Search Start -->
<!-- Service Time and Search End -->
<!-- Top Navigation Start -->
<div class="menuwrapper">
<?php $redirectTo = (is_home() || is_front_page()) ? home_url() : $_SERVER['REQUEST_URI'];?>
<?php if( ! is_user_logged_in()): ?>
<ul class="topnavi" style="float:right;">
<li><?php _e('Member Login', 'heavens_corner');?>
<!-- Login Bubble Start -->
<div id="loginbox"> <span class="logintop"> </span>
<div class="logincenter">
<h3 class="white bold upper"><?php _e('User Login', 'heavens_corner');?></h3>
<form action="<?php bloginfo('url');?>/wp-login.php" method="post" name="loginform" id="loginform">
<ul>
<li><h5 class="white"><?php _e('User Name', 'heavens_corner');?></h5></li>
<li><input name="log" type="text" class="bar" /></li>
<li><h5 class="white"><?php _e('Password', 'heavens_corner');?></h5></li>
<li><input name="pwd" type="password" class="bar" /><input type="hidden" value="<?php echo $redirectTo;?>" name="redirect_to" /></li>
<li><?php _e('Forget Password?', 'heavens_corner');?> </li>
<li class="nopading"><input type="submit" value="<?php _e('Sign in Now', 'heavens_corner');?>" class="button backcolr" /></li>
</ul>
</form>
</div>
<span class="loginbottom"> </span> </div>
<!-- Login Bubble End -->
</li>
</ul>
<?php else:?>
<ul class="topnavi" style="float:right;">
<li><?php _e('Logout', 'heavens_corner');?>
</ul>
<?php endif;?>
<?php wp_nav_menu(array('theme_location'=>'top-menu', 'container'=>false, 'menu_class'=>'topnavi')); //Top menu?>
<br />
<?php wp_nav_menu(array('theme_location'=>'main-menu', 'container'=>false, 'menu_class'=>'subnavi')); //Top menu?>
</div>
<!-- Top Navigation End -->
</div>
<ul class="boxed">
<?php get_template_part('modules/top_links');?>
<!-- Search Start -->
<li class="last">
<?php echo get_search_form(); //Search form ?>
</li>
<!-- Search End -->
</ul>
<div class="clear"></div>
<?php if($header_settings = get_option(THEME_PREFIX.'general_settings')):?>
<!--Header Short Text-->
<div class="watchlive">
<h3><?php echo character_limiter(kvalue($header_settings, 'header_text'), 50);?></h3>
</div>
<?php endif;?>
</div>
<!-- Right Header End -->
</div>
</div>
<!-- Bread Crumb Start -->
<div class="breadcrumb" style="margin-top:24px;">
<?php echo get_the_breadcrumb(); ?>
</div>
<!-- Bread Crumb End -->
<!-- Sub Page Banner Start -->
<div class="subbanner">
<?php fw_top_banner('category'); //Get big header image?>
</div>
<!-- Sub Page Banner End -->
<!-- Column 3 Start -->
<div class="col3 border-right left">
<!-- Blog Start -->
<div class="blog">
<h1 class="heading colr"><?php single_cat_title();?></h1>
<!-- Blog Post Start -->
<div class="post noborder nopading">
<?php while ( have_posts() ) : the_post(); ?>
<div class="post-date backcolr">
<span><?php echo get_the_date('j');?></span>
<span><?php echo get_the_date('M');?></span>
</div>
<div class="post-heading">
<h5><?php the_title(); ?></h5>
</div>
<div class="clear"></div>
<?php if($media = fw_post_video('w=667&h=369&showThumb=1&thumbSize=category-featured')):?>
<div class="post-thumb">
<?php echo $media;?>
</div>
<?php endif;?>
<div class="post-feat">
<ul>
<li class="authore"><?php _e('by,', 'heavens_corner');?> <?php the_author();?></li>
<li class="comments"><?php comments_number();?></li>
<?php if(has_tag()):?><li class="tags"><?php the_tags();?></li><?php endif;?>
</ul>
</div>
<div class="clear"></div>
<div class="post-desc">
<p><?php echo (function_exists('the_exerpt')) ? get_the_exerpt() : character_limiter(get_the_content(),450,'',true);?></p>
<?php _e('Keep Reading', 'heavens_corner');?>
</div>
<?php endwhile; ?>
</div>
<!-- Blog Post End -->
<!-- Pagination Start -->
<?php if($wp_query->max_num_pages > 1):?>
<div class="paginations">
<ul><?php fw_blog_pagination(); ?></ul>
</div>
<?php endif;?>
<!-- Pagination End -->
</div>
<!-- Blog End -->
</div>
<!-- Column 3 End -->
<!-- Column 1 Start -->
<div class="col1 right">
<!-- Widget Start -->
<?php fw_dynamic_sidebars('category', get_query_var('cat'));?>
<!-- Widget End -->
</div>
<!-- Column 1 End -->
</div>
<!-- Content Section End -->
</div>
<div class="clear"></div>
<!-- Footer Start -->
<?php get_footer(); ?>

Categories