Add links to taxonomy links area - drupal

I have to add a few links to where the taxonomy terms are displaying, I am using a custom module. I tried hook_link but it add links at the end of the node, How can I add links to the right side of the node title
Thank you very much

To extend Scott's answer:
you can still use your custom module with hook_link(), but you need to edit node.tpl.php or node-type.tpl.php.
i.e. the Garland node.tpl.php looks like:
<?php
// $Id: node.tpl.php,v 1.5 2007/10/11 09:51:29 goba Exp $
?>
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
<?php print $picture ?>
<?php if ($page == 0): ?>
<h2><?php print $title ?></h2>
<?php endif; ?>
<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?></span>
<?php endif; ?>
<div class="content clear-block">
<?php print $content ?>
</div>
<div class="clear-block">
<div class="meta">
<?php if ($taxonomy): ?>
<div class="terms"><?php print $terms ?></div>
<?php endif;?>
</div>
<?php if ($links): ?>
<div class="links"><?php print $links; ?></div>
<?php endif; ?>
</div>
</div>
what you need to do is move the <?php if ($links): ... block somewhere before <?php if ($submitted): ...
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
<?php print $picture ?>
<?php if ($page == 0): ?>
<h2><?php print $title ?></h2>
<?php endif; ?>
<?php if ($links): ?>
<div class="links"><?php print $links; ?></div>
<?php endif; ?>
<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?></span>
<?php endif; ?>
...
then float both the title and the links block, for example.

you could theme nodes yourself (i.e., create your own node.tpl.php or 'node-type.tpl.php') and add whatever you want after the $terms variable (or anywhere).

Related

Regular posts first (descending order), then custom post type (alphabetical) in WP search

I've been cobbling together bits and pieces of various examples together but can't seem to wrap my head around this.
I have regular blog posts (News) that I would like displayed with the most recent on top followed by a custom post type (Businesses) that I would like grouped below the News. I am using Sage and this is my first theme.
Here is my beginner code so far:
<?php get_template_part('templates/page', 'header'); ?>
<?php if (!have_posts()) : ?>
<div class="alert alert-warning">
<?php _e('Sorry, no results were found.', 'sage'); ?>
</div>
<?php get_search_form(); ?>
<?php endif; ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $post_type = get_post_type_object( get_post_type() ); ?>
<?php $type = get_post_type(); ?>
<?php if ($type == 'post') { ?>
<h2>News Results</h2>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div>
<a href="<?php the_permalink(); ?>">
<?php $cats=get_the_category(); ?>
<?php echo $cats[0]->cat_name; ?>
</a>
</div>
<div>
<h3><?php the_title(); ?></h3>
<div class="result-excerpt">
<?php if ( has_excerpt( $post->ID ) ) {
echo the_excerpt();
} else {
echo get_excerpt();
} ?>
</div>
</div>
</article>
<?php } elseif ($type == 'business') { ?>
<h2>Business Results</h2>
<article <?php post_class(); ?>>
<header>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php if (get_post_type() === 'post') { get_template_part('templates/entry-meta'); } ?>
</header>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div>
<a href="<?php the_permalink(); ?>">
<?php $cats=get_the_category(); ?>
<?php echo $cats[0]->cat_name; ?> -
<?php the_title(); ?>
</a>
<h3><?php echo the_sub_field('title'); ?></h3>
<?php if( get_sub_field('content') ): ?>
<div class="result-excerpt">
<?php echo custom_field_excerpt(); ?>
</div>
<?php endif; ?>
</article>
<?php } ?>
<?php endwhile; ?>
<?php endif; ?>
I think the problem is that you're looping over every post, in order, and deciding what to do with it. This will result in the output, whatever it is, in the same order as the input.
I don't speak very fluent PHP, but I think what's happening is that the algorithm reads like this:
-for each post:
- if it's a 'post', display it like «this»
- otherwise, if it's a 'business', display it instead like «this»
I think you want to have two loops, like this:
-for each post:
- if it's a 'post', display it like «this»
-for each post:
- if it's a 'business', display it like «this»
Unfortunately, I don't see an obvious reference to store in an array and loop over. I really don't know how sage works, so I'll have to leave the implementation to you. My best guess - and I sincerely doubt this will work - is as follows:
<?php get_template_part('templates/page', 'header'); ?>
<?php if (!have_posts()) : ?>
<div class="alert alert-warning">
<?php _e('Sorry, no results were found.', 'sage'); ?>
</div>
<?php get_search_form(); ?>
<?php endif; ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $post_type = get_post_type_object( get_post_type() ); ?>
<?php $type = get_post_type(); ?>
<?php if ($type == 'post') { ?>
<h2>News Results</h2>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div>
<a href="<?php the_permalink(); ?>">
<?php $cats=get_the_category(); ?>
<?php echo $cats[0]->cat_name; ?>
</a>
</div>
<div>
<h3><?php the_title(); ?></h3>
<div class="result-excerpt">
<?php if ( has_excerpt( $post->ID ) ) {
echo the_excerpt();
} else {
echo get_excerpt();
} ?>
</div>
</div>
</article>
<?php endwhile; ?>
<?php endif; ?>
<?php if (!have_posts()) : ?>
<div class="alert alert-warning">
<?php _e('Sorry, no results were found.', 'sage'); ?>
</div>
<?php get_search_form(); ?>
<?php endif; ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $post_type = get_post_type_object( get_post_type() ); ?>
<?php $type = get_post_type(); ?>
<?php if ($type == 'business') { ?>
<h2>Business Results</h2>
<article <?php post_class(); ?>>
<header>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php if (get_post_type() === 'post') { get_template_part('templates/entry-meta'); } ?>
</header>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div>
<a href="<?php the_permalink(); ?>">
<?php $cats=get_the_category(); ?>
<?php echo $cats[0]->cat_name; ?> -
<?php the_title(); ?>
</a>
<h3><?php echo the_sub_field('title'); ?></h3>
<?php if( get_sub_field('content') ): ?>
<div class="result-excerpt">
<?php echo custom_field_excerpt(); ?>
</div>
<?php endif; ?>
</article>
<?php } ?>
<?php endwhile; ?>
<?php endif; ?>
Good luck!

Removing date from pages not posts in search results (Wordpress)

I'm trying to remove the date from pages only in search results.
I found this: https://wordpress.org/support/topic/search-results-hide-date-for-pages-not-posts - however, I can't seem to figure out where to add it without causing errors.
I also found an answer suggesting just removing the date code from page.php but I don't have that in there anyway.
My search.php:
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="content">
<div class="article">
<?php
$wp_query->query_vars["posts_per_page"] = 16;
$wp_query->get_posts();
?>
<?php if ( have_posts() ) : ?>
<?php
global $wp_query;
$total_results = $wp_query->found_posts;
?>
<?php printf( __( 'Search results for: %s', 'shape' ), '<span>' . get_search_query() . '</span>' ); ?>
<br/><br/>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="searchresultsdate">
<?php the_time('M j, Y') ?> </div><div class="searchresults"><?php the_title(); ?></div>
<?php endwhile; ?>
</div>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<div class="right"><?php next_posts_link('Next Page »') ?></div>
<div class="left"><?php previous_posts_link('« Previous Page') ?></div>
<?php } ?>
<br><br><br>
<?php else : ?>
<div class="posttitle">Nothing found. Try something else?</div>
This page doesn't exist
<?php endif; ?>
<?php get_footer(); ?>
Change
<div class="searchresultsdate">
<?php the_time('M j, Y') ?>
</div>
to
<?php if ("page" != get_post_type()){ ?>
<div class="searchresultsdate">
<?php the_time('M j, Y'); ?>
</div>
<?php } ?>
Also you're missing ';' in many places.

ACF Repeater Field in Flexible Content

I am trying to add a repeater field into a flexible content row but for some reason nothing is being output. I have checked the fields and they seem correct so could someone please point me out to where I am going wrong? Thanks
<?php if(get_row_layout() == "collection_title"): // layout: Collection Title ?>
<div>
<h4><?php the_sub_field("collection_title"); ?></h4>
</div>
<?php elseif(get_row_layout() == "collection_images"): // layout: Collection Images ?>
<?php if(get_field('collection_images_grid')): ?>
<?php while(has_sub_field('collection_images_grid')): ?>
<div class="collections">
<span><strong><?php the_sub_field('collection_detail'); ?></strong></span>
<a href="<?php the_sub_field('product_link'); ?>">
<img src="<?php the_sub_field('collection_image'); ?>"/>
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
your <?php if(get_field('collection_images_grid')): ?> statement should be <?php if(get_sub_field('collection_images_grid')): ?>
<?php
// check if the flexible content field has rows of data
if( have_rows('the_process') ){
// loop through the rows of data
while ( have_rows('the_process') ) : the_row();
if( get_row_layout() == 'content' ){
?>
<h1><?php the_sub_field('headline');?></h1>
<h2 class="tagLine paddingBottom80"><?php the_sub_field('sub_headline');?></h2>
<div class="steps clearAfter">
<?php if(get_sub_field('process_steps')): ?>
<?php
while(has_sub_field('process_steps')):
?>
<!--Step-->
<div class="processStep rel boxSizing">
<img src="images/ph.png" width="200" height="200" class="borderRadius50Perc imageBorder boxSizing" />
<div class="processBox border1 padding20 clearAfter">
<div class="third processNumber boxSizing font70 darkBlue">
<div class="border1 padding20">
<?php echo $i;?>
</div>
</div>
<div class="twothird boxSizing processContent">
<h3><?php the_sub_field('step_headline'); ?></h3>
<div class="processContentTxt grey">
<?php the_sub_field('step_content'); ?>
</div>
</div>
</div>
</div>
<!--Step-->
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php
}
endwhile;
}
?>
You should change one thing in your code. Change <?php if(get_field('collection_images_grid')): ?> to <?php if(get_sub_field('collection_images_grid')): ?> and it will works! I've simulate your issue and after change to sub_field it works. Your code will be like this:
<?php if(get_row_layout() == "collection_title"): // layout: Collection Title ?>
<div>
<h4><?php the_sub_field("collection_title"); ?></h4>
</div>
<?php elseif(get_row_layout() == "collection_images"): // layout: Collection Images ?>
<?php if(get_sub_field('collection_images_grid')): ?>
<?php while(has_sub_field('collection_images_grid')): ?>
<div class="collections">
<span><strong><?php the_sub_field('collection_detail'); ?></strong></span>
<a href="<?php the_sub_field('product_link'); ?>">
<img src="<?php the_sub_field('collection_image'); ?>"/>
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
I had a little problems to use repeaters inside acf flexible content. So if I could say something to help in this cases is to use a variable to print the elements of repeater array, like this:
<?php if(get_row_layout() == "collection_title"): // layout: Collection Title ?>
<div>
<h4><?php the_sub_field("collection_title"); ?></h4>
</div>
<?php elseif(get_row_layout() == "collection_images"): // layout: Collection Images ?>
<?php if(get_sub_field('collection_images_grid')): ?> // considering that collections_images_grid are a repeater
<?php $collection_image = get_sub_field('collection_images_grid');?>
<?php echo $collection_image['url']; ?> <?php echo $collection_image['alt']; ?> //Or something that you would like to use [... and than the rest of code]
Assuming your repeater field is collection_images_grid, you should loop through the items with have_rows(), like this:
<?php if(get_row_layout() == "collection_title"): // layout: Collection Title ?>
<div>
<h4><?php the_sub_field("collection_title"); ?></h4>
</div>
<?php elseif(get_row_layout() == "collection_images"): // layout: Collection Images ?>
<?php if(have_rows('collection_images_grid')): ?>
<?php while(have_rows('collection_images_grid')): the_row(); ?>
<div class="collections">
<span><strong><?php the_sub_field('collection_detail'); ?></strong></span>
<a href="<?php the_sub_field('product_link'); ?>">
<img src="<?php the_sub_field('collection_image'); ?>"/>
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endif; ?>
This essentially checks if the flexible content field has rows of data (<?php if(have_rows('collection_images_grid')): ?>), and then loops through / displays them (<?php while(have_rows('collection_images_grid')): the_row(); ?>).
More details about looping through fields with have_rows(): https://www.advancedcustomfields.com/resources/have_rows/
To debug all the Advanced Custom Fields on a page and get a better understanding of the structure, I often use the following PHP snippet:
echo '<pre>';
var_dump(get_fields());
echo '</pre>';
This helps to make sure the data is available, and figure out how to reach it in the nested structure.

How to link image in the article to image itself by default in WordPress

Is there anyway i can set the image link by default to the post itself?
I don't want to set the image link in the media up loader every time.
My code that gets content for post is this:
<?php if (!$is_paged && $archives == "false") { ?>
<?php woo_image('class=thumbnail&width='.get_option('woo_home_thumb_width').'&height='.get_option('woo_home_thumb_height')); ?>
<div class="post-title">
<h3><?php the_title(); ?></h3>
<p class="post-details"><?php _e('Posted on',woothemes); ?> <?php the_time('d. M, Y'); ?> <?php _e('by',woothemes); ?> <?php the_author_posts_link(); ?>.</p>
</div>
<?php } else { ?>
<?php woo_image('class=alignleft thumbnail&width='.get_option('woo_thumb_width').'&height='.get_option('woo_thumb_height')); ?>
<h2><?php the_title(); ?></h2>
<p class="post-details"><?php _e('Posted on',woothemes); ?> <?php the_time('d. M, Y'); ?> <?php _e('by',woothemes); ?> <?php the_author_posts_link(); ?>.</p>
<!-- <div class="comment-cloud">
<?php comments_number('0','1','%'); ?>
</div> -->
<?php } ?> <?php global $more; $more = 0;?>
<?php if ( get_option('woo_content') == "true" ) { the_content('Read More >>'); } else { the_excerpt();?><?php } ?>
</div>
<!-- Normal Post Ends -->
What i do is post an image with some lines below it and the insert a read more tag.
Is there a way i can use first image in the post and link to the article, just as the title does?
At top of the page
<?php
global $post;
global $wpdb;
?>
<a href="<?php echo get_permalink($post->ID); ?>" >
<img src="your_source_here" title="image" />
</a>
get_parmalink(); will take you to the detail page of the post respectively.

Custom Blog Post Listing in Genesis Sample Child Theme

I want to add several images and divs and also customize the look of my Blog post listing... But i can't find the way to do it.
Here's the Blog Template code
<?php
/*
WARNING: This file is part of the core Genesis framework. DO NOT edit
this file under any circumstances. Please do all modifications
in the form of a child theme.
*/
/**
* Template Name: Blog
* This file handles blog post listings within a page.
*
* This file is a core Genesis file and should not be edited.
*
* The blog page loop logic is located in lib/structure/loops.php
*
* #category Genesis
* #package Templates
* #author StudioPress
* #license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
* #link http://www.studiopress.com/themes/genesis
*/
genesis();
and just above the genesis(); code.. i tried to put some divs and images there.. But i guess that's not the way it works. ..
I also tried to make my own Blog listing template using a normal wordpress code theme..
<?php /*
Template Name: List Post Pages
*/
?>
<?php get_header(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="featured">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="divider"></div>
<div id="content" class="hfeed">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
Posted in
<?php the_category(', ') ?>
|
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php genesis_after_loop(); ?>
</div>
<?php get_footer(); ?>
But no luck, what's the right way to do this?
***Update -code below is the one i want.. but instead of having the Content of the page. I want the list of Post with excerpts ....How can i do that????
<?php /*
Template Name: Page Template
*/ ?>
<?php get_header(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="featured">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="divider"></div>
<?php genesis_before_content_sidebar_wrap(); ?>
<div id="content-sidebar-wrap">
<?php genesis_before_content(); ?>
<div id="content" class="hfeed">
<?php genesis_before_loop(); ?>
<?php genesis_loop(); ?>
<?php genesis_after_loop(); ?>
</div>
<!-- end #content -->
<?php genesis_after_content(); ?>
</div>
<!-- end #content-sidebar-wrap -->
<?php genesis_after_content_sidebar_wrap(); ?>
<?php get_footer(); ?>
Im shocked that no one answered my question.. anyway, if someone bumps onto this post with similar problem. The answer is adding
<?php query_posts( $args ); ?>
just above the <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
All in all, my code looks like this ...
<?php /*
Template Name: Page Template
*/ ?>
<?php get_header(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="featured">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="divider"></div>
<?php genesis_before_content_sidebar_wrap(); ?>
<div id="content-sidebar-wrap">
<?php genesis_before_content(); ?>
<div id="content" class="hfeed">
<?php genesis_before_loop(); ?>
<?php query_posts( $args ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
Posted in
<?php the_category(', ') ?>
|
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php genesis_after_loop(); ?>
</div>
<!-- end #content -->
<?php genesis_after_content(); ?>
</div>
<!-- end #content-sidebar-wrap -->
<?php genesis_after_content_sidebar_wrap(); ?>
<?php get_footer(); ?>

Resources