Forum Replies Created

Viewing 15 replies - 1 through 15 (of 288 total)
  • Thread Starter csleh

    (@csleh)

    something clicked today and I got it!

    <?php //get first level child pages 
    		$mypages = get_pages( array( 
    		'child_of' => $post->ID, 
    		'sort_column' => 'menu_order',
    		'parent' => $post->ID ) );
    	  	foreach( $mypages as $page ) {
    	  		$mycontent = $page->post_content;
    		 	$mycontent = apply_filters( 'the_content', $mycontent );
     		?>
    <!--if has children, add div in the parent section for each child otherwise no div -->
    <?php
          $childArgs = array(
              'sort_order' => 'ASC',
              'sort_column' => 'menu_order',
              'child_of' => $page->ID
          );
          $childList = get_pages($childArgs);
          foreach ($childList as $child) { ?>
            <div class="grandchild-page">
            <h2><a href="<?php echo get_page_link( $child->ID ); ?>"><?php echo $child->post_title; ?></a></h2>
            </div>  
        <?php } ?><!--end grandchildren-->
    <?php } ?>
    <?php endwhile;  
       endif; ?>	
    • This reply was modified 6 years, 3 months ago by csleh. Reason: resolved
    Thread Starter csleh

    (@csleh)

    my logic is definitely wrong!
    I’ve tried another get pages with child_of post id in various forms, checking if ( is_page() && $post->post_parent )
    and not having any luck.

    how can i test if a page from the first get_pages results has children?

    Thread Starter csleh

    (@csleh)

    I tried this, but each first level child page is showing the “i have kids” text, instead of just the one that actually has children

      <?php $mypages = get_pages( array( 
    	'child_of' => $post->ID, 
    	'sort_column' => 'menu_order',
    	'parent' => $post->ID ) );
    	  foreach( $mypages as $page ) {
    	  	$mycontent = $page->post_content;
    		 $mycontent = apply_filters( 'the_content', $mycontent );
     		?>
     <?php $args = array( 'post_parent' => get_the_ID() );
    	$children = get_children( $args );
    	if ( ! empty($children) ) {  ?>
    		<div>i have kids</div>
    	<?php } else {?>
    		<div>im lonely</div>
    	<?php } ?> 

    can I not use the ID like this? If not, how can I find out if a page has children?

    Thread Starter csleh

    (@csleh)

    thanks but I don’t mean on the child page. Hopefully this will be a better explanation:

    On a grandparent page, use get_pages to get title, etc from all descendants
    I’d like to style like this:

    <div>child 1 page</div>
    <div>child 2 page</div>
     <div class="sub-page">grandchild page of current page (child of child 2 page)</div>
    <div>child 3 page</div>

    right now, all descendants get the same html in the foreach.
    Is there a way to add a class depending on level?
    Or an if is child of a specific page (in this example, child page 2)?
    Or do get_pages for one level deep, then get_pages within that for child pages?

    Thread Starter csleh

    (@csleh)

    OK, I got it! On the taxonomy edit screen, in the last group called “Settings”, set “Show Admin Column” to True. This will show the taxonomies for each CPT post on the CPT admin list screen.

    Thread Starter csleh

    (@csleh)

    I edit in appearance ALL THE TIME. This is the first off-the-shelf theme I’ve tried in a long time, and this is the first time files to edit how content is pulled are HIDDEN.

    I don’t want a child theme. I don’t want FTP. I don’t want to have to open elsewhere/save on a development site. I’ll just replace the call with my own loop but it would have been easier to make one change on one file. The theme won’t be used for long.

    I Can Handle It.

    Thread Starter csleh

    (@csleh)

    So here’s what I did, this is on the single page template:

    <?php $table = get_field( 'table' );
    if ( $table ) {
        echo '<table border="0">';
            if ( $table['header'] ) {
                echo '<thead>';
                    echo '<tr>';
                        foreach ( $table['header'] as $th ) {
                            echo '<th>';
                                echo $th['c'];
                            echo '</th>';
                        }
                    echo '</tr>';
                echo '</thead>';
            }
            echo '<tbody>';
                foreach ( $table['body'] as $tr ) {
                    echo '<tr>';
                        foreach ( $tr as $td ) {
                            echo '<td>';
                                echo $td['c'];
                            echo '</td>';
                        }
                    echo '</tr>';
                }
            echo '</tbody>';
        echo '</table>'; ?>
    <script>
    var headertext = [];
    var headers = document.querySelectorAll("thead");
    var tablebody = document.querySelectorAll("tbody");
    for (var i = 0; i < headers.length; i++) {
    	headertext[i]=[];
    	for (var j = 0, headrow; headrow = headers[i].rows[0].cells[j]; j++) {
    	  var current = headrow;
    	  headertext[i].push(current.textContent.replace(/\r?\n|\r/,""));
    	  }
    } 
    for (var h = 0, tbody; tbody = tablebody[h]; h++) {
    	for (var i = 0, row; row = tbody.rows[i]; i++) {
    	  for (var j = 0, col; col = row.cells[j]; j++) {
    	    col.setAttribute("data-th", headertext[h][j]);
    	  } 
    	}
    }
    </script>
    <?php } ?>

    The thead text is set as a data entry on each td, and when the table is shown on mobile each td shows that value directly above the content.
    I got the code from here:
    https://codepen.io/dudleystorey/pen/Geprd

    • This reply was modified 8 years, 1 month ago by csleh.
    • This reply was modified 8 years, 1 month ago by csleh. Reason: credit and link to code

    I build html/css first, then download an underscores theme and edit the templates to use my html. I found the template-parts confusing at first, and copied the relevant codes into single.php and page.php so the code was all viewable at a glance.

    Thread Starter csleh

    (@csleh)

    silly me. On those pages the gallery is actually from custom fields, not the default wordpress gallery, so I coded them myself. Got that one fixed. My other pages I forgot to put link to media file, not attachment page.

    Note: to get the prev/next arrows on a gallery other than wordpress default (like using Advanced Custom Fields instead, for instance), a few classes need to be added: gallery, gallery-item, and if you want captions to show in the lightbox, wp-caption-text. As always, any images that link to media file are automatically grabbed by the plugin through the link, so no extra classes needed. Without the extra classes the lightbox works, just no arrows between images in the same gallery.

    <div class="gallery">   
        <figure class="gallery-item">
            <a href="...">
     	    <img src="..." alt="..." />
            </a>
     		<figcaption class="wp-caption-text">...</figcaption>
       </figure>
    </div>

    Making this note to remind myself.
    Great plugin!

    • This reply was modified 8 years, 1 month ago by csleh.
    • This reply was modified 8 years, 1 month ago by csleh. Reason: added code sample for non-wordpress gallery to navigate through images
    Thread Starter csleh

    (@csleh)

    huh. no. I started with an underscores theme and use standard wordpress install and updates. No modifiers in the theme functions file, so I’ll check if underscores does something in one of the files not called. This is a weird one.

    Nice catch, not sure I ever would have noticed!

    Thread Starter csleh

    (@csleh)

    that would be great, thank you!

    https://dev.sullivanlehdesigns.com/work/trafficsafety-org-website/

    not the large first image in a circle, scroll a bit to the others that have captions

    Thread Starter csleh

    (@csleh)

    never mind, I got it.

    Not only did I have to check the “screen options” on the top of the screen, but under the custom post type drop down, only the posts showed by default. Simply use the “view all” tab to show the archive page to add to the menu.

    Thread Starter csleh

    (@csleh)

    it worked for basic stuff but doesn’t map to flexible layout rows. (also confusing because the flexible rows were shown twice in the dropdown, the second time with and underscore in front. i tried both). bummer.

    Thread Starter csleh

    (@csleh)

    thank you. It’s weird because the other day I could choose “custom fields” but the next section didn’t have my fields. I wonder if one page had to be published first or if the archive template had to exist or something. But it’s there now and I’m so grateful!

    Thread Starter csleh

    (@csleh)

    With the error code edited out a new form can be created, but a form cannot be edited. no orders are tracked, and even though the test email sends no other email is sent. it seems to send to paypal correctly, but doesn’t return to the correct page.

Viewing 15 replies - 1 through 15 (of 288 total)