Sidebar Category Links
-
I have these three plugins working together:
Advanced Custom Fields
Categories Image – https://zahlan.net/blog/2012/06/categories-images/
Post Tags and Categories for PagesI have custom fields set up which get applied to a page with page a page template named: Content Page
The field names are:
Page Link
Page Link NameThese are also repeater fields so more links to different pages can be added which then appear in the sidebar.
Each page has its own category and each category has a category image.
I am using this code which displays all of the links which are applied into a page with page template ‘Content Page’.
<?php foreach (get_the_category() as $cat) : ?> <img />term_id); ?>" /> <?php endforeach; ?> <?php // check if the repeater field has rows of data if( have_rows('sidebar_links') ): // loop through the rows of data while ( have_rows('sidebar_links') ) : the_row(); echo '<a class="content-page-sidebar-links" href="'; the_sub_field('page_link'); echo '"> '; the_sub_field('page_link_name'); echo '</a>'; endwhile; else : // no rows found endif; ?>
However it displays like this:
Digital Connectivity
– Internal Connectivity
– External Connectivity
– Clever Cogs
– BathroomDigital Connectivity is the category name which displays a category image in place of the category title.
– Internal Connectivity
– External Connectivity
– Clever Cogs
– Bathroomare all links.
– Bathroom is a link in a different category to
– Internal Connectivity
– External Connectivity
– Clever CogsSo bathroom should appear under a category name ‘Rooms & Areas’ and so should display the appropriate image above it, and any other links that are applied which have the category ‘Room & Areas’.
Other links could also be applied into the sidebar which may belong to other categories.
So I need to know how I can split the links in the sidebar so they appear under their correct category heading image. It also has to be automated so the code automatically knows that ‘Link A’ goes under ‘Heading A’ and ‘Link B’ goes under ‘Heading B’.
But also if no links are available for ‘Heading B’ then ‘Heading B’ should not display.
The reason this needs to be automated is because links which are applied into categories may also change categories, so it would be an administrative nightmare say if a category title was applied as a custom field at page level in the admin. These links need to be applied without any requirement to apply them under the correct heading. They should just automatically fall under the correct heading and display the correct heading image if links exist.
The page I need help with: [log in to see the link]
- The topic ‘Sidebar Category Links’ is closed to new replies.