alifhughes
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: get_previous_post() retrieves current post??Is there anything you would recommend to get the previous post and all of its data? I would use just
get_previous_post()
but I want post data such as featured image.Thanks
Forum: Fixing WordPress
In reply to: get_previous_post() retrieves current post??Ah sorry, thank you for your detailed answer, I appreciate it.
You are correct though, it didn’t die when I did the second if statement. However, it still is showing the same post in my previous post display.
I think you are right, I will not use the global namespace and try tidy things up, then it might start to work.
Thanks
Forum: Fixing WordPress
In reply to: get_previous_post() retrieves current post??Thanks for the response!
I’ve used
$post
outside of the main loop, and usedwp_reset_postdata();
after the main loop so thought that it would be fine to use it as I have been, which is why I am confused to why it isn’t working.When I use your test, it returns true, I did:
if (assert($current_post->ID != $previous_post->ID )) { die(‘Same post’); }
and it did display the
die
message.Any suggestions ?
Forum: Plugins
In reply to: [Hide My Site] After use – website description wrongBump! Having the exact same problem, really want to be able to get rid of it.
Thank you both for you answers, I looked into both but I think leejosepho suggestion of that plugin is exactly what I need.
Forum: Fixing WordPress
In reply to: Adding index (root) as a page for navigation barI have found a solution if anyone else is having problems with this.
I copied the function from Building a simple list and appended my own link to it at the end like so
$homeUrl = home_url(); $menuList .= '<li><a class="menu-item menu-item-type-post_type menu-item-object-page" href="'. $homeUrl .'">Home</a></li>';
The full code is:
<?php // Get the location of the navigation menu $locations = get_nav_menu_locations(); // Get the menu itself from the location (primary is header in my case) $menu = wp_get_nav_menu_object($locations['primary'] ); // Get the menu items $menuItems = wp_get_nav_menu_items($menu->term_id); // Initialise a string to hold the unorded list $menuList = '<ul id="menu-' . $menuName . '">'; // Iterate through each menu item from the list of all menu items and append // Name of menu item and url to its page foreach ( (array) $menuItems as $key => $menuItem ) { $title = $menuItem->title; $url = $menuItem->url; $menuList .= '<li><a href="' . $url . '">' . $title . '</a></li>'; } // Get the link to home url (in my case root (localhost/wordpress/) $homeUrl = home_url(); // Append own link $menuList .= '<li><a href="'. $homeUrl .'">Home</a></li>'; // Close the unordered list tag $menuList .= '</ul>'; // Echo the list back to html echo $menuList; ?>
The problem in my case is that using
wp_nav_menu($menuItems);
would mean that the hardcoded list item I needed to add wasn’t included in the unordered list that the function automatically created, thus causing styling problems.
This unpacks the list, appends own custom link, and displays it.Forum: Fixing WordPress
In reply to: Adding index (root) as a page for navigation barDo you mean in the actual HTML code? I have tried but my custom styling and JavaScrip doesn’t seem to like the combination of both.