Active menu state in wordpress - 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'); ?>

Related

How to make a post page in 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();

Archive displayed on a custom page to be used in menu structure

I would like to direct users to appropriate archive pages from within the menu. If I want this I need a page that I can attach to the menu.
How would I display the exact same stuff as on the archive page (archive.php) on another page so that pagination and functionalities remain the same, but some stuff will be taken from the actual page ? (can create custom page template of course)
I'll still have to show a sidebar for the page that you visited and not archive's sidebar
Breadcrumbs path will still have to show current menu item position and not archive page path
To show sidebar from the actual page is of most importance here.
EDIT
What I want to achieve is this actually:
Lets say I have a page
http://my.page/subpage/something/notifications/
I want that on this page, I can display exactly the same stuff as on the certain archive page which is here:
http://my.page/subpage/notification/
('notification' is a custom post type here)
I already have a solution that displays all archive stuff on another page (created a page template for that), but its a bit complicated to display title, breadcrumbs and sidebar properly for each page, since some of these should stay the same as they would be, but some should take the value of another site.
You can create a custom page template and assign it to a page. On that page you can use get_posts() to query the posts you want, like this:
global $post;
$posts = query_posts( /* Your args here*/ );
foreach($posts as $post) {
setup_postdata($post);
// Do your stuff as in archive.php
}
wp_reset_postdata();

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

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.

adding single.php page to wordpress or if condition for main page or post detail page

I use Barecity Theme for WordPress. i built everything, but now i need to add a single.php file to theme. now it displays all post content at homepage, I created a short_desc Custom Field. and I call it from code with;
<?php //get_post_meta($post->ID, 'short_desc', true); ?>
it is fine. but i need to display this short desc at home page listing, and the main content at details page. how can do that?
I appreciate helps!!
It sounds like what you are trying to do is show a custom field that you have set on a post on the index page (which lists all the posts).
To do that you'll need to modify index.php by adding your snippet where you would like to have the short description.
<?php echo get_post_meta($post->ID, 'short_desc', true); ?>
You need to use echo to display the results from the get_post_meta function.
Depending on how your posts are setup you can also use the More button when you write your posts. This will cut off your post at a certain point that you decide and only show that short part on the index and archive pages.
Another option would be to use
<?php the_excerpt(); ?>
Which shows the first 55 words (this can be adjusted though) of the post.
Hope that helps,
Paul

Resources