How to make a post page in wordpress? - wordpress

I have been searching on google but unable to find any proper tutorial. Can anyone tell me how do i make my own post page in wordpress?
For Example:
In wp-admin, There is already a Post option in menu..
Post>Add New
Post>All
Post>Categories
Post>Tags
In Add New, There is a blog form, where we can add post but I want another option in Menu.. called Licenses, Then option of Add New, When i click on it, There will be a form, What I have to do is to add Featured image in it and add title of it and publish and then it should show on license page. Demo License
Similarly I want another Trades, in which I should add trades and it should show on trades pages. Note, the trade page and license page will have different Style for showing, different Css. In Trade page there will be a boostrap accordion which will show trades, Demo Trades
Similarly I want another page for this affiliation page.. Demo Aff IN this page, there are some images with title, and sometimes client send more images, so i want a form in my wp-admin where i can just upload image and show on page like im showing. It will show differently for all pages.
How will i achieve this? Any suggestions? Any other method? im totally new to wordpress

You can create your own page template. Here is the reference
In your template directory create a new file like page-anyhing.php
Add this to your start of the file:
<?php
/**
* Template Name: Anything
*
* #package WordPress
*/
Then, when you create a new post, at the right side of the dashboard, you can select the Anything from Page Template menu.
You need to build your page template by PHP and HTML codes.
UPDATE
Based on OP comment:
You need to create a new template, eg. affiliates as I mentioned above.
When you get a new affiliate, then you can create a post, and add Category: Affiliates.
In your page template you need to get posts by categories:
$query = new WP_Query( array( 'category_name' => 'affiliates' ) );
Here is the reference from WP_Query.
if ($query->have_posts()) {
echo '<ul>';
while ($query->have_posts()) {
$query->the_post();
echo '<li><h2>' . get_the_title() . '</h2><div>Show image here</div></li>';
}
echo '</ul>';
} else {
echo "Sorry, no affiliates...";
}
/* Restore original Post Data */
wp_reset_postdata();

Related

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
**/

Add items to portfolio page via dashboard

In one theme (FloZo) I've seen a nice functionality and I would like to learn how to make something similar. It's about a portfolio page, take a look at the demo "Our Work section".
You create a page and give it a template (Work archive) via Pages menu - more or less understood
You don't add any pictures there!
In your Dashboard you have a nice "work" section, where you can choose "make a new work item" - you add pictures with titles and descriptions there. - This is the big trick!
Now: my newbie idea on how it works:
The template is just the "body" of the page with the title
The dashboard "work" section must be doing something like this:
When you post a work item, it pastes/appends the whole item code into your page (like an item template code) with your specific image and text. It also creates an item-specific page (it's where you end up after clicking on an item).
My question is: is there any slightest possibility to add such a functionality to a Wordpress theme?
Here is how I see it:
The page template, 'Work Archive' has the loop that is displaying posts of 'Work' post type.
So to achieve this first you have to add the custom post type of your liking, and then in the page template add a custom loop to display these:
<?php
$args = array(
'post_type' => 'your_post_type',
'posts_per_page' => -1 //or whatever you choose
);
$work_query = new WP_Query($args);
if ($work_query->have_posts()) : while ($work_query->have_posts()) : $work_query -> the_post(); ?>
<!-- loop content goes here -->
<?php
endwhile;
endif;
wp_reset_postdata(); // always reset post data after custom loops
?>
If you need more info pleae don't hesitate to ask.
Happy coding!

wordpress : how to add categories and tags on pages?

I have generated pages using a custom template by creating a php file in my theme directory
something like :
<?php
*
* Template Name: Contact Page
*/
?>
<html ..... </html>
and then adding a new page on the dashboard selecting this new template
How can i now associate tags and categories to each pages ?
Is creating posts instead of pages the only solution?
Even better is to add to functions.php in your theme folder:
function myplugin_settings() {
// Add tag metabox to page
register_taxonomy_for_object_type('post_tag', 'page');
// Add category metabox to page
register_taxonomy_for_object_type('category', 'page');
}
// Add to the admin_init hook of your theme functions.php file
add_action( 'init', 'myplugin_settings' );
Tried using the accepted answer but for some reason it only shows the Post types and none of the Pages shows in the category page. E.g. /category/entertainment/
To fix that, I have to do this:
// add tag and category support to pages
function tags_categories_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}
// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');
Try this:
add_action( 'init', 'wpse34528_add_page_cats' );
function wpse34528_add_page_cats(){
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
Not at all helpful to say 'download plugin' for beginners who are most likely not going to have downloaded wordpress and are therefore not able to install said plugin. Here is some short code for those like me that have been scouring the web for something that actually works on regular pages with regular accounts - ie you're not a developer.
First, make sure you have your pages in your menu set up properly.
YOU DO NOT NEED TO MAKE YOUR PAGES 'Categories' or 'Tags'!
This wouldn't give you actual pages to then go and edit, so if you are wanting to add sliders, text, an intro, or anything for that matter, you wouldn't be able to.
Then go to WP Admin > Pages
Select a page to edit and go to the text editor instead of visual editor (far right hand side tab)
Then past the following short code:
[display-posts category="hair,makeup,reviews,beauty" posts_per_page="10" include_date="true" text-decoration: none date_format="F j, Y" order="DESC" include_excerpt="true" wrapper="div" image_size="large"]
<
(The shortcode collects all the posts that you have assigned certain categories in your blog posts i.e. mine was hair and beauty. So obviously change yours to ones that are appropriate. It then allocates how many posts (mine was 10), the date (in descending order,) with a large image and an excerpt of the post)
this plugin sorted me out :
http://wordpress.org/extend/plugins/add-tags-and-category-to-page/
with the standard instructions :
Upload the plugin files to the /wp-content/plugins/ directory
Activate the plugin through the 'Plugins' menu in WordPress
Use the setting page of the plugin from Settings > Add Tags And Category For Page.

Active menu state in wordpress

I have two blog pages: other one gets all post from one category and the other gets all post from all other categories. And Im using the new menu system that was introduced in 3.0.
Now the problem is that when user is on lets say on category2 single post page, but still in the menu the category1 has active state class.
On both categories, single post uses same template (the default one).
Well that's easy there is a nice post on that here, put this in the function.php file within your theme.
<?php function insertAds($content) { $content = $content.'<hr />Have you visited WpRecipes today?<hr />'; return $content; } add_filter('the_excerpt_rss', 'insertAds'); add_filter('the_content_rss', 'insertAds'); ?>

Resources