I created a custom theme for word-press. When i say 'add new' page and i put content into this page it only displays the footer and header but dosnt hook my content which is in the CMS on that page.
This is what i have : page.php
<?php get_header(); ?>
<div class="row">
<div class="col-sm-12">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; endif;
?>
</div> <!-- /.col -->
</div> <!-- /.row -->
<?php get_footer(); ?>
Its been a long day what am i doing wrong here. Any tips please?
Would also like to make like a parent page from this new page, but its only option with page attributes are 'default template'.
If you didn't have a template part please use the_content() instead of
get_template_part( 'content', get_post_format() );
My actual problem, resolved. So i used 'advanced custom field' plugin for my WordPress. The problem using this is that it still requires you to do some coding.
I added a new page.
For that page I had an header image and content. So for ACF(advanced custom field) that is equal to two field types "Image --> field type and Text-Area --> field type"
Field name is what i used to call the fields to my .php page template.
Field Name : Image = header-image
Field Name : (2)Text Area = header-image-text-top (and) header-image-text-author
(I needed to display my text on the image thats why my div is just based on header image.)
So I hooked my page template and then added the the hooks for the fields i want to display on this page template.
page-stay.php :
<?php
/*Template Name: Stay - Parent Page */
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(); ?>
<article id="post=<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- <header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header>(you can use this if you need your page header to display)-->
<div class="enry-content">
<?php
$image = get_field('header-image');
if( !empty($image) ): ?>
<div class="head-image">
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<div class="head-text-box">
<div class="head-text-box-holder">
<p class="headtext-quote"><?php the_field('header-image-text-top'); ?></p>
<p class="headtext-author"><?php the_field('header-image-text-bottom'); ?></p>
</div>
</div>
</div>
<?php endif; ?>
</article>
<?php endwhile; ?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_footer(); ?>
Related
My Wordpress blog works fine on the main page that shows all posts, however, when I click a category the most recent post's title becomes the main header and that post doesn't even show up in the blog post list of that category.
https://ibb.co/ebReRV
I spied on other people with the same theme as me and they have the same problem so I believe this is a problem with the original code. My theme's creator seems to have disappeared and hasn't responded to any of my messages.
archive.php
<section id="wp-main-content" class="clearfix main-page title-layout-standard">
<?php do_action( 'naturalfood_before_page_content' ); ?>
<div class="container">
<div class="main-page-content row">
<!-- Main content -->
<div class="content-page <?php echo esc_attr($main_content_config['class']); ?>">
<div id="wp-content" class="wp-content">
<?php get_template_part('templates/layout/archive') ?>
</div>
</div>
You Need to Create Archive Page
Give Archive Page name is "archive.php".
Archive Page Structure Like this:
<?php
/*
Template Name: Archives
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
/* Custom Archives Functions Go Below this line */
/* Custom Archives Functions Go Above this line */
</div><!-- .entry-content -->
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I am trying to insert meta slider to display above my posts in wordpress.
I correctly inserted the code in the theme index.php file above the loop. it works correctly, but it also displays on top of the side bar as well, and i would like it just above the posts.
is there any advice on how i can do this? where in the loop would i need to insert it?
here is what i have
<?php
/**
* The main template file
*
* #package SimpleMag
* #since SimpleMag 1.0
**/
get_header();
global $ti_option;
?>
<?php $archive_sidebar = get_field( 'page_sidebar', get_option('page_for_posts') ); ?>
<section id="content" role="main" class="clearfix animated">
<?php
echo do_shortcode("[metaslider id=437]");
?>
<?php if ( $ti_option['posts_page_title'] == 'full_width_title' ) : ?>
<header class="entry-header page-header">
<div class="wrapper title-with-sep page-title">
<h1 class="entry-title">
<?php
$posts_page_id = get_option( 'page_for_posts' );
echo get_the_title( $posts_page_id );
?>
</h1>
</div>
</header>
<?php endif; ?>
<div class="wrapper">
<?php
// Enable/Disable sidebar based on the field selection
if ( ! $archive_sidebar || $archive_sidebar == 'page_sidebar_on' ):
?>
<div class="grids">
<div class="grid-8 column-1">
<?php endif; ?>
<?php if ( $ti_option['posts_page_title'] == 'above_content_title' ) : ?>
<header class="entry-header page-header">
<div class="title-with-sep page-title">
<h1 class="entry-title">
<?php
$posts_page_id = get_option( 'page_for_posts' );
echo get_the_title( $posts_page_id );
?>
</h1>
</div>
</header>
<?php endif; ?>
<div class="grids <?php echo $ti_option['posts_page_layout']; ?> entries">
<?php
if ( have_posts() ) : while ( have_posts()) : the_post();
get_template_part( 'content', 'post' );
endwhile;
?>
</div>
<?php ti_pagination(); ?>
<?php else : ?>
<p class="message">
<?php _e( 'Sorry, no posts were found', 'themetext' ); ?>
</p>
<?php endif;?>
<?php
// Enable/Disable sidebar based on the field selection
if ( ! $archive_sidebar || $archive_sidebar == 'page_sidebar_on' ):
?>
</div><!-- .grid-8 -->
<?php get_sidebar(); ?>
</div><!-- .grids -->
<?php endif; ?>
</div><!-- .wrapper -->
</section><!-- #content -->
<?php get_footer(); ?>
As long as the sidebar is deactivated, your placement is fine. When the sidebar is active you should place it just below <div class="grid-8 column-1">. That's the beginning of the main area of your page, next to the sidebar. (I'm guessing the div is using something similar to bootstrap, taking up 8 of 12 available grids).
To prevent future updates of your theme to overwrite your customizations, if this is in fact a supported theme, you should also consider creating a child theme. It's real easy and is explained here: https://codex.wordpress.org/Child_Themes
I am trying to target individual posts so I can change the css (title tags, padding, etc) of specific posts. My Wordpress site currently generates the posts in a loop.
index.php code (brings in content.php which has 'post' code)
<div>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part( 'content' );
?>
<?php endwhile; ?>
<div class="clearfix"></div>
<div class="col-md-12">
</div>
<?php else : ?>
<?php get_template_part( 'no-results', 'index' ); ?>
<?php endif; ?>
</div>
content.php code (gets post-title, category, and sets post-thumbnail to background-image)
<?php
if (has_post_thumbnail()) {
$thumbnail_data = wp_get_attachment_image_src(get_post_thumbnail_id( get_the_ID()), 'my-fun-size' );
$thumbnail_url = $thumbnail_data[0];
}
?>
<article id="post-<?php the_ID(); ?>" style="background-image:url('<? php echo $thumbnail_url ?>')" <?php post_class('container-fluid'); ?> >
<div class="row">
<div class="col-md-12">
<h2><?php the_title(); ?></h2>
<?php the_category(', '); ?>
</div>
</div>
</article><!-- /#post -->
functions.php (setting image size)
add_theme_support( 'post-thumbnails' );
add_image_size('my-fun-size', 'thumbnail');
The output is 'rows' 100% width with the title, category and background-image (feature-image). Stacked on top of each other. I want to be able to target the text and bg-image of different posts to make them each look different.
i think the best way to to this is by adding a custom field inside your posts, then, in your templates, you call that custom field this way:
get_post_meta($post->ID, 'name_of_your_custom_field', true);
this must be inside the loop.
Below you can see my home page template. I used to have this line in the content of my page, it loads the thumbnail and the video player with video. I now want to have this in a template but i dont know how to call it properly. You can see I am trying to call the video from my theme options panel.
Before
[KGVID poster="http://www.muratgokmen.co.uk/wp-content/uploads/2013/09/thumbnail-home.jpg" width="1005" height="565"]http://www.muratgokmen.co.uk/wp-content/uploads/2013/09/sample.mp4[/KGVID]
After
[KGVID poster="http://www.muratgokmen.co.uk/wp-content/uploads/2013/09/thumbnail-home.jpg" width="1005" height="565"]http://www.muratgokmen.co.uk/wp-content/uploads/2013/09/sample.mp4[/KGVID]
Any help would be much appreciated.
<?php /* Template Name: Home Page */ get_header(); ?>
<!-- section -->
<section role="main">
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!-- article -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
[KGVID poster="http://www.muratgokmen.co.uk/wp-content/uploads/2013/09/thumbnail-home.jpg" width="1005" height="565"]<?php echo $smof_data['home-page-video-url'];?>[/KGVID]
</article>
<!-- /article -->
<?php endwhile; ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>
</section>
<!-- /section -->
<?php get_footer(); ?>
For using shortcode in templates do this
<?php echo do_shortcode("[KGVID poster='http://www.muratgokmen.co.uk/wp-content/uploads/2013/09/thumbnail-home.jpg' width='1005"' height='565']http://www.muratgokmen.co.uk/wp-content/uploads/2013/09/sample.mp4[/KGVID]"); ?>
I'm using the below code on index.php file of twentyeleven
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
<?php twentyeleven_content_nav( 'nav-above' ); ?>
<?php query_posts('cat=4&showposts='.get_option('posts_per_page')); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="post-thumb-title">
<?php the_post_thumbnail(array(632,305));?>
<p class="thumb-title"><?php the_title(); ?></p>
</div>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
As you can see from the code above, I'm only showing the posts with Cat ID = 4 and I'm using css to overlay the title on the image thumbnail which is generated using the function "the_post_thumbnail" with a custom size.
The issue is that the frontpage is only showing the title of the posts and thumbnail only for the 1st post.
You can see the website here: http://fusion.fusionconstruction.co.uk/
Links to other posts with category ID 4 selected:
http://fusion.fusionconstruction.co.uk/fusion-media-at-revolution-round-1/
http://fusion.fusionconstruction.co.uk/fusion-launch-new-website-for-dean-downing/
I would like to display all the posts similar to the 1st one.
Thanks!
<?php query_posts('cat=4&showposts='.get_option('posts_per_page')); ?>
should probably be
<?php query_posts('cat=4&showposts='.get_option('posts_per_page')); ?>
That is, you shouldn't urlencode the ampersand. Hopefully this is what is messing up your query.
Also, the_post_thumbnail() will show the post's featured image, so for it to produce a thumbnail you need to make sure that all the posts have a featured image.