Forum Replies Created
-
AuthorPosts
-
October 9, 2015 at 12:46 pm in reply to: How to correct the link code in my custom field function #167745Carla the MooseMember
You have an accent!!
I've seen you in the forums for years and never knew you're from a different country.
Anyway, I watched the video yesterday and wasn't able to resolve this problem.
:o)
Carla the MooseMemberI enjoyed learning how to add the shortcode myself, but I do remember reading about this plugin. Thanks for the reminder.
Using this plugin, are you able to insert shortcode between two paragraphs of text on a page or blog post and have it display correctly?
Carla the MooseMemberFrom what I've read, there doesn't seem to be a straightforward solution to getting a shortcode widget to neatly display when inserted in page text. So I added text to the widget and deal with it that way.
Carla the MooseMemberAck, it's me again. There sure are a lot of coyote heads in this thread.
Here's the code. I noticed something that I didn't think to question. The before and after code ... not sure what it does. Could this be hanging up the shortcode and placing it first on the page?
// MAILCHIMP WIDGET genesis_register_sidebar( array( 'id' => 'mailchimp', 'name' => __( 'MailChimp widget', 'moose' ), 'description' => __( 'Adds a widget on the subscribe page.', 'moose' ), ) ); function mailchimp() { genesis_widget_area( 'mailchimp', array( 'before'=> '<div class="mailchimp widget-area">', 'after' => '</div>', ) ); } add_shortcode( 'chimpcode', 'mailchimp' );
Carla the MooseMemberI can't figure this out, so I've removed everything on the page except the shortcode and added the text to the widget.
I should be able to place the shortcode where I want it on the page, in between the two paragraphs. But I'm stuck. I'll have to come back to this another day and see if I can get it to work.
Carla the MooseMemberI removed the hyphen in the shortcode name. If I'm understanding the codex correctly, numbers and underscores are okay, but not hyphens. It still didn't adjust the placement. Shouldn't the shortcode appear where I place it within the body of the page?
Carla the MooseMemberSince the shortcode will tell it where to go, I guess I don't need add_action or the conditional statement for it to display on a specific page. I removed that from the function, and it displays just fine, but it shows up at the top of the page and not between the two paragraphs.
So now I need to fiddle with placement. This is where I'm stuck. I'd love some guidance, thanks.
Carla the MooseMemberI found the shortcode page in the codex:
https://codex.wordpress.org/Shortcode_API
I added this outside of the widget function:
add_shortcode( 'mailchimp-shortcode', 'mailchimp' );
It works, and I didn't have to add anything to register shortcodes. But it's displaying after the text I wrote for the page instead of being inserted in between two paragraphs, and there's another subscribe form displaying, probably because of the hook I specified.
Still tinkering and learning.
Carla the MooseMemberSure, but be forewarned: These are changes I made directly to a Genesis file. NOT a good idea. When I have some time, I'm going to write a proper function for my child theme.
Thanks to Brad's guidance, I found the code in genesis/lib/structure/post.php. Here it is. Copy this to a text editor, and then open a blank document and copy the original post.php contents and save it.
Search for XXX and you'll see what I did. There are six of them. The first marks the beginning of the section where you'll find the code. This is just that section. I only wanted numbers to display, so I also removed the previous/next text links, including the invisible but present anchor link.
ETA: For the $paged code, where you see XXX is the line I removed to limit the numbered links to display only one on either side of the active link. I hope that makes sense. Just compare with the original code and you'll see what I removed.
add_action( 'genesis_after_endwhile', 'genesis_posts_nav' ); /** XXX * Conditionally echo archive pagination in a format dependent on chosen setting. * * This is shown at the end of archives to get to another page of entries. * * @since 0.2.3 * * @uses genesis_get_option() Get theme setting value. * @uses genesis_prev_next_posts_nav() Prev and Next links. * @uses genesis_numeric_posts_nav() Numbered links. */ function genesis_posts_nav() { if ( 'numeric' === genesis_get_option( 'posts_nav' ) ) genesis_numeric_posts_nav(); else genesis_prev_next_posts_nav(); } /** * Echo archive pagination in Previous Posts / Next Posts format. * * Applies <code>genesis_prev_link_text</code> and <code>genesis_next_link_text</code> filters. * * @since 0.2.2 */ function genesis_prev_next_posts_nav() { $prev_link = get_previous_posts_link( apply_filters( 'genesis_prev_link_text', '« ' . __( 'Previous Page', 'genesis' ) ) ); $next_link = get_next_posts_link( apply_filters( 'genesis_next_link_text', __( 'Previous Page', 'genesis' ) . ' »' ) ); $prev = $prev_link ? '<div class="pagination-previous alignleft">' . $prev_link . '</div>' : ''; $next = $next_link ? '<div class="pagination-next alignright">' . $next_link . '</div>' : ''; $nav = genesis_markup( array( 'html5' => '<div %s>', 'xhtml' => '<div class="navigation">', 'context' => 'archive-pagination', 'echo' => false, ) ); $nav .= $prev; $nav .= $next; $nav .= '</div>'; if ( $prev || $next ) echo $nav; } /** XXX * Echo archive pagination in page numbers format. * * Applies the <code>genesis_prev_link_text</code> and <code>genesis_next_link_text</code> filters. * * The links, if needed, are ordered as: * * * previous page arrow, * * first page, * * up to two pages before current page, * * current page, * * up to two pages after the current page, * * last page, * * next page arrow. * * @since 0.2.3 * * @global WP_Query $wp_query Query object. * * @return null Return early if on a single post or page, or only one page present. */ function genesis_numeric_posts_nav() { if( is_singular() ) return; global $wp_query; //* Stop execution if there's only 1 page if( $wp_query->max_num_pages <= 1 ) return; $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1; $max = intval( $wp_query->max_num_pages ); //* Add current page to the array if ( $paged >= 1 ) $links[] = $paged; //* Add the pages around the current page to the array if ( $paged >= 3 ) { $links[] = $paged - 1; //* XXX } if ( ( $paged + 2 ) <= $max ) { //* XXX $links[] = $paged + 1; } genesis_markup( array( 'html5' => '<div %s>', 'xhtml' => '<div class="navigation">', 'context' => 'archive-pagination', ) ); $before_number = genesis_a11y() ? '<span class="screen-reader-text">' . __( 'Page ', 'genesis' ) . '</span>' : ''; echo '<ul>'; //* Previous Post Link REMOVED XXX //* Link to first page, plus ellipses if necessary if ( ! in_array( 1, $links ) ) { $class = 1 == $paged ? ' class="active"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), $before_number . '1' ); if ( ! in_array( 2, $links ) ) echo '<li class="pagination-omission">…</li>'; } //* Link to current page, plus 2 pages in either direction if necessary sort( $links ); foreach ( (array) $links as $link ) { $class = $paged == $link ? ' class="active" aria-label="' . __( 'Current page', 'genesis' ) . '"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $before_number . $link ); } //* Link to last page, plus ellipses if necessary if ( ! in_array( $max, $links ) ) { if ( ! in_array( $max - 1, $links ) ) echo '<li class="pagination-omission">…</li>' . "\n"; $class = $paged == $max ? ' class="active"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $before_number . $max ); } //* Next Post Link REMOVED XXX echo '</ul></div>' . "\n"; }
Carla the MooseMemberI've been a fan of yours for years, Brad. You've helped me a number of times.
:o)
Carla the MooseMemberAck, the brain is hurting.
So I did a major no-no and worked directly with the post.php file in Genesis. I couldn't get the function to work because I wasn't understanding the core function. My site hasn't launched, and I made a copy of this file in case I messed up.
The end result:
I reduced the number of page links that display on either side of the current page, allowing for no more than 5 page links in total. I also removed the previous and next text links. You have to remove the entire code or it leaves behind a text-less hyperlinked space you'll discover when you hover over it.
Now, I need to work on learning how to write a function.
Carla the MooseMemberBrad, if you're seeing this, have you come up with a way to modify numbered pagination for mobile devices? I much prefer numbered page links over "next" and "previous" links. But they break onto a second line in smaller windows.
I'm still hammering out the code for my website. The five links I want displayed won't break in small windows, but lots of people display the full amount, and that can split onto another line depending on how much content they have.
Carla the MooseMemberI've now managed to remove the dang function, which is good. It's like learning to crawl before you stand up and walk.
The problem was, I was using genesis_numeric_posts_nav instead of genesis_posts_nav.
It all looks the same in the post.php file. But now it's glad to be properly removed when called by its proper name.
Carla the MooseMemberThanks, I'll explore that discussion.
I'm doing this in my child theme.
Carla the MooseMemberNow I'm this far. And once again, nothing white screened at me. Things are still alive.
My test is changing the previous page text to hello page. When I see hello, I'll know I'm getting there. And next page is now doggy page. This is just for testing purposes.
So far, it's not working. It must have something to do with the filter or not removing the default or something along those lines. I'm getting there, though.
//* MODIFY NUMBERED PAGINATION add_filter( 'genesis_numeric_posts_nav', 'sp_numeric_posts_nav' ); function sp_numeric_posts_nav() { if( is_singular() ) return; global $wp_query; //* Stop execution if there's only 1 page if( $wp_query->max_num_pages <= 1 ) return; $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1; $max = intval( $wp_query->max_num_pages ); //* Add current page to the array if ( $paged >= 1 ) $links[] = $paged; //* Add the pages around the current page to the array if ( $paged >= 3 ) { $links[] = $paged - 1; $links[] = $paged - 2; } if ( ( $paged + 2 ) <= $max ) { $links[] = $paged + 2; $links[] = $paged + 1; } genesis_markup( array( 'html5' => '<div %s>', 'xhtml' => '<div class="navigation">', 'context' => 'archive-pagination', ) ); $before_number = genesis_a11y() ? '<span class="screen-reader-text">' . __( 'Page ', 'genesis' ) . '</span>' : ''; echo '<ul>'; //* Previous Post Link if ( get_previous_posts_link() ) printf( '<li class="pagination-previous">%s</li>' . "\n", get_previous_posts_link( apply_filters( 'genesis_prev_link_text', '« ' . __( 'hello Page', 'genesis' ) ) ) ); //* Link to first page, plus ellipses if necessary if ( ! in_array( 1, $links ) ) { $class = 1 == $paged ? ' class="active"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), $before_number . '1' ); if ( ! in_array( 2, $links ) ) echo '<li class="pagination-omission">…</li>'; } //* Link to current page, plus 2 pages in either direction if necessary sort( $links ); foreach ( (array) $links as $link ) { $class = $paged == $link ? ' class="active" aria-label="' . __( 'Current page', 'genesis' ) . '"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $before_number . $link ); } //* Link to last page, plus ellipses if necessary if ( ! in_array( $max, $links ) ) { if ( ! in_array( $max - 1, $links ) ) echo '<li class="pagination-omission">…</li>' . "\n"; $class = $paged == $max ? ' class="active"' : ''; printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $before_number . $max ); } //* Next Post Link if ( get_next_posts_link() ) printf( '<li class="pagination-next">%s</li>' . "\n", get_next_posts_link( apply_filters( 'genesis_next_link_text', __( 'doggy Page', 'genesis' ) . ' »' ) ) ); echo '</ul></div>' . "\n"; }
Carla the MooseMemberWell, if I weren't broke I'd certainly pay for access to your blog post.
I'll keep plugging away on this. Thank you.
Carla the MooseMemberHere's how far I got so far.
I tried removing the function to replace it with the modified one. It didn't go away. So I figured I'll deal with that later. Just to show myself I'm capable of at least doing something easy, I added the pagination to the header. It's temporary.
I copied the code from the codex and nothing died. No white screens. But nothing has changed, either. The only change I did, as a test, was to add hello to the previous text. It doesn't show up. So nothing died, but nothing was rebirthed, either.
Genesis must be using different names or code. I can't just paste that section from post.php into my functions file. That's where things turned white and died. So I have to write a function. Any tips on what to do next?
//* MODIFY NUMBERED PAGINATION add_action( 'genesis_header', 'genesis_numeric_posts_nav' ); add_filter( 'genesis_numeric_posts_nav', 'sp_numeric_posts_nav' ); function sp_numeric_posts_nav() { echo paginate_links( array( 'base' => '%_%', 'format' => '?page=%#%', 'total' => 1, 'current' => 0, 'show_all' => False, 'end_size' => 1, 'mid_size' => 2, 'prev_next' => True, 'prev_text' => __('« hello'), 'next_text' => __('Next »'), 'type' => 'plain', 'add_args' => False, 'add_fragment' => '', 'before_page_number' => '', 'after_page_number' => '' ) ); }
Carla the MooseMemberI've never written my own function before, but thanks for getting me started. I didn't look hard enough in the files.
I was able to see the link and code, thank you. I'm not sure why it disappeared.
Carla the MooseMemberMost of the Genesis files are largely empty and call other files I can't find.
Carla the MooseMemberFrom what I was able to find, it seems the code is in the includes file, not Genesis. There's a links file where the pagination is listed. But I couldn't make sense of what I was seeing. I couldn't find anything that looked similar to what I found in the codex.
I browsed Genesis and didn't see anything. I'll take another look.
-
AuthorPosts