Problems with img src and template pages Wordpress - wordpress

I am building a Wordpress website from HTML/CSS/JS templates i made earlier. However this is my first time using it and im really struggling. There are plenty of resources and solutions however none seem to be working for me, for example; one tutorial pointed out you could create template pages if you go into your management screen > pages > add new > page attributes > template. But under page attributes is only "order" although it does claim there should be a template bit if you click help.
I've managed to link my stylesheet but none of my images are appearing. They are all in a folder named images within my theme directory.
In my external stylesheet i have:
body{
background:url("images/subfolder/image01.jpg");
}
I have also tried:
body{
background-image:url("images/subfolder/image.jpg");
}
In my html I have:
<img src="<?php echo get_template_directory_uri(); ?>/images/subfolder/image02.png" alt="DESCRIPTION" />
I have also tried:
<img src="<?php bloginfo('template_directory'); ?>/images/subfolder/image02.png" alt="DESCRIPTION" />
I can't seem to get any of these up.

Here is the deal:) Your folder structure "must" look like this
-Yourtheme Folder
index.php
style.css
page.php
single.php
...other files
-images (images folder)
-js (js folder)
So if you are developing a theme full image path will not help you much because you simply don't know how will your clients domain look, like it can be http://www.mydomain.com/somefolder/ but it can also be http://www.mydomain.com/somefolder/subfolder/anothersubfolder so to access your images use relative paths like this:background-image:url('../images/myimage.jpg'); that way images will work no matter how your domain path will look.
Now to templates:)
In order to wordpress recognize that you are having a template create a file and name it mycooltemplate.php (you can name it however you want)
Your first line inside your template file must read something like this:
<?php /*Template name: This is my cool template*/
?>
That way wordpress will know that you are using a template and you can access it inside
management screen > pages > add new > page attributes > template
So to give a real world example let's create our first template shall we?
We will now create an simple archive template.
Open your text editor and add this code
<?php
/*
Template Name: My Cool Archives Template
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php the_post(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php get_search_form(); ?>
<h2>Archives by Month:</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
<h2>Archives by Subject:</h2>
<ul>
<?php wp_list_categories(); ?>
</ul>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Save it as archives.php (name it however you want) and upload it to your theme folder. So now your folders should look like this:
-Yourtheme Folder
index.php
style.css
page.php
single.php
archives.php (your first template yeeey!!)
...other files
-images (images folder)
-js (js folder)
Hope this helps...

Try specifying the full path to the themes directory from your web root.
eg. /wp-content/themes/[yourtheme]/images/subfolder/image01.jpg

The image paths should work in your CSS but in your HTML/PHP you will need to use something like
<img src="<?php bloginfo('stylesheet_directory'); ?> /images/subfolder/image02.png" />

Related

src of the custom-logo img-tag is missing and not rendered in Wordpress

I'm using the template "Twentyseventeen" and created a child theme of it.
Now I added the_custom_logo(); to header.php and the custom-logo link is rendered,
but without the img src. So I have a blank space. I searched now for hours and can't find the reason. Even if I switch back to orignal Twentyseventeen theme the img src was missing. Well I'm not very famiiar to wordpress and if anybody could help me to fix this? Thank you
Hi :) try to add <img> like this
<img src="<?php the_custom_logo();?>"/>
In my theme I use This:
<div class="logo">
<a href="<?php echo get_home_url(); ?>">
<?php $logo_id = get_theme_mod( 'custom_logo' );?>
<?php echo wp_get_attachment_image( $logo_id , 'full' ); ?>
</a>
</div>
I hope that it help you :)
Possibly you don't have custom logo set in the backend or it needs a reset.
Go to the Admin Dashboard > Appearance > Customizer > Site Identity
Check if you've set the custom logo there. If it is set, remove it
and reset it.
If you don't see any option to set custom logo there, your theme doesn't support custom logo option. In this case the_custom_logo() or related functions will not work. Read this guide to add support for custom logo and then using the URL or printing the logo with markup.

WordPress and Visual Composer custom page template

I really hope somebody can help me.
I'am working with visual composer and whould like to create a template to use on some page's.
I whant to create the first section in pure code and save it in my theme's as a template file.
Then when i pick this template in the page editor, i whould like to use visusal composer, but content made with composer should go below, what i have done in my theme's templatefile.
So if my template file in my theme folder contains a big image and some buttons, then i whant to output visual composer content below it.
Is that at all possible.?
When i try to pick another template file then the default i just get a blank output containing header and footer but no content from visual composer. When i use the default template, all works.
I whant to create a file where i can tell visual composer where to output content, hope it makes sense.
Kind regards
Dannie
Yes this is possible.
Below is a code-example of the template file where you can add your custom code wherever you like.
Name your file like this example-page.php
The ID's and classes are of course optional.
<?php
// Template Name: Your name
get_header(); ?>
<!-- Your custom code goes here -->
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<div class="container">
<!-- Or here, if you want it inside your container -->
<div>
<?php
while ( have_posts() ) : the_post();
the_content(); // Will output the content of visual composer
endwhile; // End of the loop.
?>
</div>
</div><!-- END container -->
</main><!-- #main -->
</div><!-- #primary -->
Need more instructions? Please let me know :)

Adding Wordpress header into a subfolder page

Okay. I have wordpress installed on the root. I also have uploaded a subfolder within wordpress. www.mysite.com/subfolder/ I want to be able to add some php pages inside the subfolder because I need it to call some scripts. I just want to be able to add the wordpress header into it. The pages come up but when I add the wordpress header it all goes blank or just does nothing.
I have tried...
'
<?php include 'http://www.mywebsite.org/wp-blog-header.php'; ?>
<?php require('http://www.mywebsite.org/wp-blog-header.php');?>
and tried
<?php include 'http://www.mywebsite.org/wp-content/themes/MYTHEME/header.php'; ?>
<?php require('http://www.mywebsite.org/wp-content/themes/MYTHEME/header.php');?>
and
<?php include './wp-content/themes/MYTHEME/header.php'; ?>
<?php require('./wp-content/themes/MYTHEME/header.php');?>
Nothing seems to be working.
Any help would be great...Thank you.
Looks like the problem is you're including the URL to wp-blog-header.php, you should instead include the relative path, then call get_header(); as usual. So you should have something like this:
<?php
require('/the/path/to/your/wp-blog-header.php');
get_header();
?>
Check out the Integrating WordPress with Your Website Codex entry.

create a different index.php for post in wordpress

I'm working on a wordpress that has, among other things, a Front Page and a Post Page for showing news.
From what I understand, the template that the Post Page uses, is the index.php, but the index.php is also used by other pages.
The thing is that I want to create a special page for post, with a header that says news, etc., but I don't want other pages to use that template.
Is there a way to create an alternative index.php (index_news.php) that is only used to show posts?
That way I can use index_news.php for the post and index.php for everything else.
Thanks
EDIT //////////
My first option was to create a new page-template (news.php) with the loop inside, and then, in the the wordpress options, targeted the post to that new page (news.php).
But when I do that, it loads the index.php not the news.php template. Maybe is something wrong with the loop. Here is the loop I'm using:
<!-- Start the Loop. -->
<div class="post">
<!-- Display the Title as a link to the Post's permalink. -->
<h2><?php the_title(); ?></h2>
<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
<!-- Display the Post's content in a div box. -->
<div class="entry">
<?php the_content(); ?>
</div>
<!-- Display a comma separated list of the Post's Categories. -->
<p class="postmetadata">Posted in <?php the_category(', '); ?></p>
</div> <!-- closes the first div box -->
<!-- Stop The Loop (but note the "else:" - see next line). -->
<?php endwhile; else: ?>
<!-- The very first "if" tested to see if there were any Posts to -->
<!-- display. This "else" part tells what do if there weren't any. -->
<p>Sorry, no posts matched your criteria.</p>
<!-- REALLY stop The Loop. -->
single.php - is for one post view, but if You wolud like to modify blog index, than you could also create a custom template (page-news.php) with a header that allows it to be separated as page template:
<?php
/*
* Template Name: News Page
* #package WordPress
*/
?>
and then use loop inside of it.
But for this case what I think is even better, You can modify header.php and use wordpress conditional tags such as:
is_front_page(), is_page() or any that will work for You: http://codex.wordpress.org/Conditional_Tags
There are many ways to do same ;).

creating wordpress template

I need to create a fresh wordpress template using adobe dreamweaver . I want the template with image slider , stylish menus and commenting options. please guide me from basic to end.
Maybe you'll find this tutorial helpful:
http://www.adobe.com/devnet/dreamweaver/articles/dw-wordpress-multiscreentheme.html
as well as this:
http://www.adobe.com/devnet/dreamweaver/articles/dw_wordpress_pt1.html
Wordpress Template starts with
<?php /* Template Name: Stylish Template */ ?>
<?php get_header(); ?> // go to header.php add required js file for slider & menu through wordpress function() <?php wp_nav_menu($args); //check wordpress documentation for $args.
<div id="slider">
--images will go here
</div>
<div id="content">--Content Goes here---These will be posts from any category or latest posts, look wordpress documentation for <?php comment_template() to add comments if they are disabled.?></div>

Resources