Jul18
Javascript, PHP, Web Development, Wordpress
I’m developing a new site that has a navigation that is built dynamically via wordpress’ wp_list_pages function
<?php wp_list_pages('sort_column=menu_order&title_li=&exclude=6'); ?>
Navigation items that have submenus (css dropdowns) are still clickable, but for this website they have no content. I wanted a way to make those items unclickable. I was unable to find any way with wordpress’ api, but I did find a way with jquery.
$('#navigation > li > a').filter(
function() {
return $(this).siblings().length == 1
}
).attr( 'href', '#' ).attr( 'onClick', 'return false' );
This sets the href to ‘#’, and onClick to ‘return false’ of all navigation links that have submenus. Make sure to change the navigation id to reflect your site.
Nov22
Web Development
This tutorial is aimed at developers who just want wordpress to function as a lightweight CMS, that is wordpress will only be used for editing page content.
First install wordpress in whatever directory you want the admin to live. I chose /admin.
Any page that needs to use wordpress functionality you must add this:
require('/path/to/wp-blog-header.php');
This gives you access to wordpress functions that we need:
- get_page – Get the page data from the database
- wpautop – Automatically add paragraph tags to page content
To get page content:
$page_data = get_page( 4 ); // Where 4 is the page ID in wordpress
There is a bug in certain versions of php, if you get the error:
Fatal error: Only variables can be passed by reference…
Then use this format instead:
$page_id = 4;
$page_data = get_page( $page_id );
$page_data now contains all of the info for that page, and is ready for use in your templates/views. Check the function reference to see the data you have available to you.
To display post_content use the wp function wpautop.
<?= wpautop($page_data->post_content) ?>
It’s simple!