How can make content editable Wordpress - wordpress

I am working on wordpress site, I want to make all pages content editable from backend i.e admin panel,every page site have many sections so not easy to handle only with page content area.
What is the most easiest and preferable way to make all content editable.

add page in the admin panel with the contents that you needed to show in the front page. then using the page ID you can get the contents in your template page.
<?php
$id=47;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>

Related

Featured Image URL outside of Loop

I have a page on my Wordpress website called Blog, this is set to a static page and is the Blog page so it has a list of blog posts. On the blog page I have a featured image set. I want to use this featured image as a background image on the Blog page.
home.php (template for blog page):
At the top of home.php before the Loop that pulls the list of blog posts I have:
<?php
$page_id = get_queried_object_id();
if ( has_post_thumbnail( $page_id ) ) :
$image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $page_id ), 'optional-size' );
$image = $image_array[0];
else :
$image = get_template_directory_uri() . '/images/default-background.jpg';
endif;
echo $image;
?>
<div class="feature" style="background-image: url('<?php echo $image; ?>')"></div>
This works and it sets the featured image. However it seems to have set the featured image on every single page on the website to the featured image from the Blog page. Even after I changed the featured image on the About Us page it still pulls the URL for the Blog page's featured image and sets that as the featured image on the About Us page.
I have the website here: http://www.cqwebdesign.co.uk/Action-Harpenden-Physiotherapy/
As you can see by these screenshots I have set different featured images on the Blog and About page:
http://i.imgur.com/DnU8V9F.jpg
http://i.imgur.com/qshulWT.jpg
Anyone know how I can fix this?
As the home.php template affects only your Blog Page, it would be interesting how your page.php template code looks like (Notice: page.php is the default template for pages like your 'About' Page) and why the featured image isn't shown correctly on this page(s).
Try to debug or echo your id values for the Blog Page and the About Page and verify if the corresponding page id is the same as the one referred by get_queried_object_id();.
I think you're having a page.php template but just in case, if you don't have one please notice Wordpress' Template Hierarchy
Wordpress Codex:
When the static front page feature is configured properly, WordPress will not use a Custom Page Template to display the blog posts index, even if a Custom Page Template is assigned to the page designated as the "Posts page". WordPress will only use either home.php or index.php.

How to show page title in blog post of wordpress site

I want to show the page title in single post page of wordpress theme. I tried to use <?php echo get_the_title() ?> but it return the post title, not the page title.
basically I want to show MY page title, in this case "Blog" below my header area in single.php file. how do I make it?
In order to get page title you need to use WordPress API function use the code below
<?php
$post_7 = get_post($id);
$title = $post_7->post_title;
?>
In wordpress both posts and pages have ids. So same function will work to get title of either post or page.
You have to pass this parameter to get the title of the page.
For reference see this link
http://codex.wordpress.org/Function_Reference/get_post

How to fetch Page ID in wordpress

I am using this code to bring the content out of the page.
<?php
$page = get_page_by_title( 'page-title' );
$title = $page->post_title;
echo "<h3>" . $title . "</h3>";
$content = apply_filters('the_content', $page->post_content);
echo $content;
?>
Now, i want to get the content and title by using page ID.
If any one has the answer?
You can use the get_post() function
$myPost = get_post(17);
echo $myPost->post_title;
Per your comment:
Is there any way i can avoid putting id in the direct code. eg. just
making a page and content from back-end it reflects in front-end. i am
making a onepage website. can it will be done by any kind of loop or
something like that.
I bolded that word because if this is the case there's a very simple solution, but there are many ways to reach it.
Option 1:
If you're familiar with the WordPress Template Hierarchy you'll know you can create a PHP paged called front-page.php. Then you can create 1 single page under Pages, once that's done you can go to Settings -> Reading and click the radio button which allows you to
Set a static page (select below)
You can then select the page you created. This will automatically use the front-page.php template versus page.php.
Option 2:
You can copy your page.php template and rename it to use a pages slug. For instance, if I create a page called "Contact Us" WordPress will automatically make a slug that looks like contact-us which is part of the web URL to view the page. I can then copy page.php and rename it page-contact-us.php so when you view the "Contact Us" page, it will automatically use this page template.
Option 3:
Finally you can directly create a Page Template where you select it from a drop down in the Admin Panel when you create a new page. All you have to do is copy your page.php template file and call it whatever you want, something standard like page_template-contact or something of the sort. Then you can add this direct above your get_header() call:
/**
Template Name: My Custom Page
**/

How to differentiate Front page and other pages in Wordpress?

I have created a front page (i.e index.php) with my own design. This page will contain
header got from <?php get_header(); ?> [has navigation bar code]
Then some content. Here I'm showing three thumbnails of posts. [has slider, thumbnail posts etc]
And a footer from <?php get_footer(); ?>[has footer links]
The problem is, I see index.php loaded correctly as a front page. But when I navigate to other pages like About or Contact, the respective content from these pages is not showing up. Instead what getting loaded there is, same what Index page has. I don't want slider or thumbnail appearing on these pages.
So how to tell wp that, this is my front page, and this is my About page, don't load a slider and stuff on About page!?
use is_front_page() to determine the home page. like you only want slider on the home page then edit your header.php file that consist the slider part and do something like this
if( is_front_page() ):
// Front Page stuff like slider and
// whatever you want
endif;
Try this ,
if( is_home() || is_front_page() ){
//your home page content
}
else{
//other pages
}
For more here
Hope its works..
Make another template and set this template for your single pages. And then from backhand set it.
I usually create a front-page.php file, Wordpress will use that instead of index.php (which you can use as a generic template from then on).

How to change header in Wordpress Blog page and all Post pages only

How to change header in Wordpress Blog page and all Post pages only.
I want a custom header in Blog page and all single posts page.
Thanks
You can use conditional tags within Wordpress:
http://codex.wordpress.org/Conditional_Tags
Basically, you will need to create the content you want only for the blog and post pages and wrap this within the conditional tags:
P.S Don't forget to include the category, and archive pages - as well as the post pages.
is_single(), is_archive(), is_category()
<?php if (is_single()) { ?>
// This is a post page
<?php } else { ?>
//This is not a post page
<?php } ?>
Hope this helps.
To include different header for specific pages change get_header($name) function call inside templates and add $name attribute. Wordpress will load header-{name}.php if file exists, if not, default header header.php will be loaded. Check out template hierarchy for templates where you need to change get_header() function call ( single.php, page.php ).
Wordpress documentation:
get_header
template hierarchy

Resources